안드로이드 개발 질문/답변
(글 수 45,052)
File file = new File(파일경로);
HttpURLConnection conn = (HttpURLConnection) new URL(FileInfo.fileUrl).openConnection(); //커넥션 호출
conn.setRequestProperty("Range", String.format("bytes=%s-", Long.toString(file.length()))); //파일길이를 Range프로퍼티에 셋팅
InputStream is = conn.getInputStream();
FileOutputStream fos = new FileOutputStream(file);
byte[] buffer = new byte[1024];
int read = 0;
while ((read = is.read(buffer)) != -1) { // 파일 쓰기 시작
fos.write(buffer, 0, read);
fos.flush();
}
대충 코드는 이렇습니다.
이어받기 구현중인데 파일이 깨지네요.. 많은 도움 부탁드립니다.
HttpURLConnection conn = (HttpURLConnection) new URL(FileInfo.fileUrl).openConnection(); //커넥션 호출
conn.setRequestProperty("Range", String.format("bytes=%s-", Long.toString(file.length()))); //파일길이를 Range프로퍼티에 셋팅
InputStream is = conn.getInputStream();
FileOutputStream fos = new FileOutputStream(file);
byte[] buffer = new byte[1024];
int read = 0;
while ((read = is.read(buffer)) != -1) { // 파일 쓰기 시작
fos.write(buffer, 0, read);
fos.flush();
}
대충 코드는 이렇습니다.
이어받기 구현중인데 파일이 깨지네요.. 많은 도움 부탁드립니다.