Java tutorial
//package com.java2s; //License from project: Apache License import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; public class Main { 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) { } return -1; } }