Android 複製單個檔案到指定目錄,Android copy file
阿新 • • 發佈:2018-11-29
package com.angding.util; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; /** * @author 鄧孟鑫 */ public class FileUtils { public static boolean fileCopy(String oldFilePath,String newFilePath) throws IOException { //如果原檔案不存在 if(fileExists(oldFilePath) == false){ return false; } //獲得原檔案流 FileInputStream inputStream = new FileInputStream(new File(oldFilePath)); byte[] data = new byte[1024]; //輸出流 FileOutputStream outputStream =new FileOutputStream(new File(newFilePath)); //開始處理流 while (inputStream.read(data) != -1) { outputStream.write(data); } inputStream.close(); outputStream.close(); return true; } public static boolean fileExists(String filePath) { File file = new File(filePath); return file.exists(); } }
好了就到這裡,如果以上程式碼存在問題請將您寶貴的意見提出來,非常感謝