java中的文件的复制
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
/**
* 文件的复制
*
* @author wuzl
*
*/
public class test05 {
public static void copy(String str, String target) {
File strFile = new File(str);
File targetFile = new File(target);
try {
InputStream in = new FileInputStream(strFile);
OutputStream out = new FileOutputStream(targetFile);
byte[] bytes = new byte[1024];
int len = -1;
while ((len = in.read(bytes)) != -1) {
out.write(bytes);
}
in.close();
out.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args) {
copy("C:\\Users\\25316\\Desktop\\wu\\test03.txt", "C:\\Users\\25316\\Desktop\\test03.txt");
}
}