Skip to content

老哥,现在这个库少了FileUtil这个类, #1

Description

@roybill

我现在通过这样子写了一个从assets拷贝文件到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();
}`

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions