나는이 이상한 문제에 휩싸였다. 이 코드를 사용하여 MP3 파일을 다운로드 할 때다운로드 jpg, apk 파일은 열리지 만 mp3 파일은 열 수 없음
public boolean downloadSection(String link,String fileLocation,long currentlyDownloadedBytes){
try {
RandomAccessFile file = new RandomAccessFile(fileLocation, "rw");
file.seek(currentlyDownloadedBytes+1);
URL imageUrl = new URL(link);
HttpURLConnection conn =(HttpURLConnection)imageUrl.openConnection();
conn.setRequestProperty("Range", "bytes=" + currentlyDownloadedBytes + "-");
conn.setConnectTimeout(100000);
conn.setReadTimeout(100000);
conn.setInstanceFollowRedirects(true);
InputStream is=conn.getInputStream();
byte buffer[]=new byte[1024];;
while (true) {
// Read from the server into the buffer
int read = is.read(buffer);
if (read == -1) {
break;
}
// Write buffer to file
file.write(buffer, 0, read);
}
file.close();
return true;
} catch (Exception ex){
ex.printStackTrace();
return false;
}
}
가 downloades가 잘 열어 파일, 그러나 다운로드 안드로이드 응용 프로그램 (의 .apk 파일) 을 제공합니다 : 나는 파일을 다운로드하려면 다음 방법을 사용하고
패키지 구문 분석 오류이 열리고 이미지가으로 열리지 않습니다. 도와주세요
는
죄송 다운로드되어 있는지 확인하는 것입니다 여기에 설명해. 그리고 찾는 동안 currentlyDownloadedBytes에 1을 더하면 문제가 발생합니다. 모두 잘 지금 :) –