import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;import java.util.LinkedList;import java.util.List; //文件複製 // ...
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
//文件複製
//E:/3.jpg ---> D:/1.jpg
public class CopyFileByIo {
public static void main(String[] args) {
FileInputStream fis=null;
FileOutputStream fos=null;
try {
//輸入流讀取 E:/3.jpg
fis=new FileInputStream("E:/3.jpg");
//輸出流
fos=new FileOutputStream("D:/1.jpg");
//位元組緩衝區
byte[] buffer=new byte[1024];
int len=0;
while((len=fis.read(buffer))!=-1){
fos.write(buffer, 0, len);
fos.flush();
}
System.out.println("複製成功!");
} catch (Exception e) {
e.printStackTrace();
} finally{
try {
fos.close();
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}