안드로이드 개발 질문/답변
(글 수 45,052)
지금 제가 웹서버에 zip 파일 2M 가 정도 되는걸
앱 내부에서 다운로드 받는데
40초가 넘게 걸리네요
근데 브라우저에서 url 로 입력 해서 다운 받으니
5초도 안걸리는데
혹시 다운받는 방법중
String src = "서버 파일 이름";
String des = "저장할 경로";
InputStream in = null;
OutputStream out = null;
OutputStream out = null;
try{
in = new BufferedInputStream(new URL("src).openStream());
out = new BufferedOutputStream(new FileOutputStream(des));
in = new BufferedInputStream(new URL("src).openStream());
out = new BufferedOutputStream(new FileOutputStream(des));
int read;
while(true)
{
read = in.read();
if(read == -1) break;
out.write(read);
}
in.close();
out.close();
} catch (FileNotFoundException e) {
System.out.println("catch -> FileNotFoundException");
} catch (IOException e) {
System.out.println("catch -> IOException");
} finally {
if (in != null) try {in.close();System.out.println("in.close()");} catch (IOException e) {System.out.println("in.finally -> IOException");}
if (out != null)try {out.close();System.out.println("out.close()");} catch (IOException e) {System.out.println("out.finally -> IOException");}
}
while(true)
{
read = in.read();
if(read == -1) break;
out.write(read);
}
in.close();
out.close();
} catch (FileNotFoundException e) {
System.out.println("catch -> FileNotFoundException");
} catch (IOException e) {
System.out.println("catch -> IOException");
} finally {
if (in != null) try {in.close();System.out.println("in.close()");} catch (IOException e) {System.out.println("in.finally -> IOException");}
if (out != null)try {out.close();System.out.println("out.close()");} catch (IOException e) {System.out.println("out.finally -> IOException");}
}
이방법 보다 빠른 방법 아시는분 없을까요
읽어 주셔서 감사 합니다




fos = new FileOutputStream(target); // target은 File 객체입니다. bos = new BufferedOutputStream(fos); int bufferLength = 0; totalLength = 0; byte[] buffer = new byte[1024]; // 버퍼 크기에 따라 속도가 달라질 수 있습니다. while((bufferLength = is.read(buffer)) > 0) { // bos.write()로 파일을 쓸 수 있습니다. bos.write(buffer, 0, bufferLength); Thread.sleep(1); // 없으면 더 빠릅니다만 진행바 등을 사용하시면 있는 것이 자연스럽습니다. }더 빠른지는 모르겠네요. 근데 2메가가 40초라니.. ㅎㄷㄷ;;