웹에서 이미지를 받아서 로컬 메모리에 저장하는 루틴입니다.
하지만 무엇이 잘못됐는지는 몰라도 Writing을 하다가 그냥 멈춰버립니다. 아무런 Exception도 뜨지 않고 while문에 머물다가 Time out 나서 Force Close popup이 뜹니다. 그런데 문제는 이 현상이 매번 일어나지는 않는다는 겁니다. 가끔가다 이러니 미치겠습니다.
 
private void saveImage(String fullPath) {
    File imgFile = new File(fullPath);
    try {
        if(imgFile.exists()) boolean b = imgFile.delete();
   
        URL url = new URL(this.fileURL);
        URLConnection connection = url.openConnection();
        HttpURLConnection httpConnection = (HttpURLConnection)connection;
        InputStream in = httpConnection.getInputStream();
   
        FileOutputStream fos = new FileOutputStream(imgFile);
        int n = 0;
        while((n = in.read()) != -1) {
            fos.write(n);
        }
        fos.close();
    } 
    catch(IOException e) {
        imgFile.delete();
        Log.d("IOException Thrown", e.toString());
    }
 }
로그로 찍어본 결과 While 문에서 문제가 생깁니다. 그런데 문제는 while에서 in.read시 -1이 넘어오지 않아 무한 루프가 도는 것 같지는 않고
그냥 write가 안되는 것 같습니다. 파일이 저장되는 폴더를 살펴보면 4576 byte까지 쓰다가 그냥 멈춰있고 조금 지나서 force close 팝업이 뜨네요.. 10번에 2-3번 꼴로 발생합니다. 희한하게도 writing이 멈추는 시점이 언제나 똑같다는 거죠(4576byte)

여러 고수님들의 도움이 절실히 필요합니다..도와주세요.~~~