/* 웹에서 파일 다운로드하기 * Stream을 이용하여 웹에서 파일을 다운로드하고 * 어플 내의 data공간에 파일을 저장한다. * db등의 파일을 다운로드할때 유용하다. */

File outfile = new File("/data/data/어플패키지명/databases/다운받을 파일명");

InputStream is = new BufferedInputStream(new URL("FileUrl").openStream());

OutputStream fo = new BufferedOutputStream(new FileOutputStream(outfile)); int read = 0; byte[] buffer = new byte[1024]; while ((read = is.read(buffer, 0, 1024)) != -1) fo.write(buffer, 0, read); fo.flush(); fo.close(); is.close();

위 소스 기반으로 파일을 다운을 받고 DDMS로 확인을 하면


다운로드 전


다운로드 후


이런식으로 파일이 변한것을 확인할 수 있습니다.


+ Recent posts