androidcopy文件

androidcopy文件

public static int copyFile(String fileDir, String fileName, byte[] buffer) {
    if (buffer == null) {
        return -2;
    }

    try {
        File file = new File(fileDir);
        if (!file.exists()) {
            file.mkdirs();
        }
        File resultFile = new File(file, fileName);
        if (!resultFile.exists()) {
            resultFile.createNewFile();
        }
        BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(
                new FileOutputStream(resultFile, true));
        bufferedOutputStream.write(buffer);
        bufferedOutputStream.flush();
        bufferedOutputStream.close();
        return 0;

    } catch (Exception e) {
        e.printStackTrace();
    }
    return -1;
}

你可能感兴趣的:(android,string,buffer)