안드로이드 개발 질문/답변
(글 수 45,052)
안녕하세요
압축파일을 다운받아서 파일을 이동시키는 소스를 짰는데요
다른 스마트폰에서는 잘 작동되는데
딱 갤3에서만 null에러가 나더라고여 아무리 찾아봐도
이유를 모르겠네요 ㅜㅜ
퍼미션도추가해줬는데 ....
고수님들 도움 부탁드려요
에러 부분은 fos.close(); 에 null 에러입니다.
/////////////////////소스
private void downloadDB(HttpURLConnection Conn, String FileName) {
Toast.makeText(getApplicationContext(), "DataBase를 다운로드 중입니다.\n잠시만 기다려주세요.", Toast.LENGTH_SHORT).show();;
// 웹페이지에서 다운받은 db파일을 해당 패키지 db로 저장한다.
final String DIR ="/data/data/"+getApplication().getPackageName()+"/databases/";
final String PATH = DIR+ FileName;
Log.d("test","DIR:"+DIR);
File fDir = new File(DIR);
File f = new File(PATH);
FileOutputStream fos = null;
BufferedOutputStream bos = null;
InputStream is = null;
BufferedInputStream bis = null;
try {
URL url = new URL("http://www.cstotalbox.co.kr/saudiDatabase.db);
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
if(!fDir.exists()){
fDir.mkdir();
}
if (f.exists()) {
f.delete();
f.createNewFile();
}
is = httpConn.getInputStream();
bis = new BufferedInputStream(is);
if(isNotEmptyObj(is)){
Log.d("test","make dir");
}
fos = new FileOutputStream(f);
bos = new BufferedOutputStream(fos);
int read = -1;
int len = Conn.getContentLength();
byte[] buffer = new byte[len];
while ((read = bis.read(buffer, 0, 1024)) != -1) {
bos.write(buffer, 0, read);
}
bos.flush();
Log.d("test", "write sucess");
} catch (IOException e) {
// TODO Auto-generated catch block
Log.d("test", "file Write error");
} finally {
try {
fos.close();
bos.close();
is.close();
bis.close();
} catch (IOException e) {
}
}
}




sdk4.0부터 메인스레드에서 인터넷 관련 작업을 못하는 걸로 알고있습니다.
스레드에서 작업해보세요.