解決Assert目錄下沒法拷貝超大文件到SD卡的問題

 Assert 目錄文件拷貝時候, Android 有個規定就是文件大小不能操做1M, 否則會拋文件太大的錯誤. 解決辦法以下. 將文件拷貝到類文件下: spa

 代碼示意以下: 
 private static boolean copyFile(Context ctx, String filename, String des) {
  InputStream instream = null;
  try {
   if (filename.contains("TUIRes.ndt")) { //這個文件超過1M
    instream = XmlFile.class.getResourceAsStream("TUIRes.ndt"); 
   } else if (filename.contains("TUpdateRes.ndt")) {
    instream = XmlFile.class.getResourceAsStream("TUpdateRes.ndt");
   } else {
    instream = ctx.getAssets().open(filename);
   } get

   copyFile(des, instream);
   return true;
  } catch (Exception e) {
   return false;
  }
 } it

 private static void copyFile(String fileToPath, InputStream in)
   throws Exception {
  OutputStream out = null;
  try { io

   out = new FileOutputStream(fileToPath);
   byte[] buffer = new byte[1024];
   while (true) {
    int ins = in.read(buffer);
    if (ins == -1) {
     break;
    } class

    out.write(buffer, 0, ins);
   }
  } finally {
   if (in != null) {
    in.close();
   }
   if (out != null) {
    out.flush();
    out.close();
   }
  }
 } stream

相關文章
相關標籤/搜索