본문 바로가기

자료

assets 파일을 특정 폴더에 복사하기


  InputStream is = null;
  FileOutputStream fos = null;
  File outDir = new File("/data/data/com.TestApp.main/databases/");
  outDir.mkdirs();

  try {
   is = getAssets().open("codedata.db");
   int size = is.available();
   byte[] buffer = new byte[size];
   File outfile = new File(outDir + "/" + "codedata.db");
   fos = new FileOutputStream(outfile);
   for (int c = is.read(buffer); c != -1; c = is.read(buffer)){
    fos.write(buffer, 0, c);
   }
   is.close();
   fos.close();
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }