특정주소의 그림파일 또는 동영상 파일을 다운로드 받는 로직입니다.
보시다시피 정말 간단합니다.
private Runnable fileDownLoad = new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
URL url = null;
HttpURLConnection conn = null;
InputStream is = null;
BufferedInputStream bis = null;
FileOutputStream fos = null;
BufferedOutputStream bos = null;
try {
url = new URL("http://blog.joins.com/usr/s/i/sima4020/1/명화150.jpg");
conn = (HttpURLConnection) url.openConnection();
Log.i("URLConnection", conn.toString());
is = conn.getInputStream();
bis = new BufferedInputStream(is, 1024);
fos = new FileOutputStream(StoragePath.LOCAL_PATH + "/EndersGame.jpg");
bos = new BufferedOutputStream(fos);
byte[] buff = new byte[1024];
int byteRead = 0;
while((byteRead = bis.read(buff, 0, 1024)) != -1) {
Log.i("down", ""+byteRead);
fos.write(buff, 0, byteRead);
fos.flush();
}
bos.close();
fos.close();
bis.close();
is.close();
}catch(Exception ee) {Log.i("Exception", ee.toString());}
}
};
파일을 다운로드 받는 로직중 쓰레드 부분입니다.
디버깅을 걸어보면 is = conn.getInputStream(); 여기서 자꾸 걸려서
확인해보니 계속 java.io.FileNotFoundException 이 발생하네요.
다른 경로의 동영상이나 이미지주소를 넣어도 똑같네요;;
원인을 못찾겠습니다.
살려주세요.