안드로이드 개발 질문/답변
(글 수 45,052)
Assets 폴더에 있는 default DB 파일을 복사하려는데, AssetFileDescriptor는 DB 파일의 정보를 받아올 수 없는건가요?
처음 어플 실행시 Assets/database 폴더에 있는 default.db 파일은 어플의 databases 폴더에 복사하려고 합니다.
코드 수행 중에 AssetFileDescriptor가 FileNotFoundException을 발생 시키네요.
db 파일은 정보를 받아올 수 없는 건가요?
뭐가 문제인지 알 수가 없네요.
File outfile = new File("/data/data/com.paad.citys/databases/default.db"); if(outfile.length() > 0) return; AssetManager assetManager = getResources().getAssets(); try { InputStream is = assetManager.open("database/default.db", assetManager.ACCESS_BUFFER); AssetFileDescriptor af = assetManager.openFd("database/default.db"); // FileNotFoundException 발생 long filesize = af.getLength(); byte [] tempdata = new byte[(int)filesize]; is.read(tempdata); is.close(); outfile.createNewFile(); FileOutputStream fo = new FileOutputStream(outfile); fo.write(tempdata); fo.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }
이미 2번째 올리는 글이지만,
첫번째 올릴 때 공지사항을 다 읽었다고 적지 않아서 여기다 적습니다.
공지사항 다 읽었습니다.