个人存档
assets目录通过流的形式存储到sd卡的制位置
/*** * 调用方式 * * String path = Environment.getExternalStorageDirectory().toString() + "/" + "Tianchaoxiong/useso"; String modelFilePath = "Model/seeta_fa_v1.1.bin"; Assets2Sd(this, modelFilePath, path + "/" + modelFilePath); * * @param context * @param fileAssetPath assets中的目录 * @param fileSdPath 要复制到sd卡中的目录 */ public static void Assets2Sd(Context context, String fileAssetPath, String fileSdPath){ //测试把文件直接复制到sd卡中 fileSdPath完整路径 File file = new File(fileSdPath); if (!file.exists()) { Log.d(TAG,"************文件不存在,文件创建"); try { copyBigDataToSD(context, fileAssetPath, fileSdPath); Log.d(TAG, "************拷贝成功"); } catch (IOException e) { Log.d(TAG, "************拷贝失败"); e.PRintStackTrace(); } } else { Log.d(TAG,"************文件夹存在,文件存在"); } } public static void copyBigDataToSD(Context context, String fileAssetPath, String strOutFileName) throws IOException { InputStream myInput; OutputStream myOutput = new FileOutputStream(strOutFileName); myInput = context.getAssets().open(fileAssetPath); byte[] buffer = new byte[1024]; int length = myInput.read(buffer); while(length > 0) { myOutput.write(buffer, 0, length); length = myInput.read(buffer); } myOutput.flush(); myInput.close(); myOutput.close(); }新闻热点
疑难解答