import java.io.FileInputStream; import java.io.FileOutputStream; import org.junit.Test; public class JavaIO { @Test public void test() throws Exception{ //1、輸入輸出路徑 String inputPath = "C:\\Users\\zwx474555\\Desktop\\E04D24C1-BB2F-424A-AD2D-7B770C96F9A1.png"; //圖片路徑 String outPath = "F:\\123.png"; //復制路徑及文件名 //2、輸入輸出流對象 FileInputStream fis = new FileInputStream(inputPath); FileOutputStream fos = new FileOutputStream(outPath); //3、聲明字節數組,每次按1K讀取,按1K輸出 byte[] bytes = new byte[1024]; int temp = 0; while((temp = fis.read(bytes)) != -1){ fos.write(bytes, 0, temp); //一邊讀取,一邊輸出 } //4、刷新輸出流 fos.flush(); //5、關閉流 fis.close(); fos.close(); } }