將某個文件複製到指定目錄。
package com.file;
import java.io.*;
public class test4 {
public static void main(String[] args) {
FileInputStream fis = null;
FileOutputStream fos =null;
try {
fis = new FileInputStream("d:\\qlg.jpg");
fos = new FileOutputStream("e:\\qlg_復件.jpg");
byte []buf = new byte[1024];
int n = 0;
while ((n=fis.read(buf)) != -1){
fos.write(buf); //輸出到指定文件
}
} catch (Exception e) {
// TODO 自動生成的 catch 塊
e.printStackTrace();
}finally{ //關閉流
try {
fis.close();
fos.close();
} catch (IOException e) {
// TODO 自動生成的 catch 塊
e.printStackTrace();
}
}
}
}