简单实现I/O文件复制

来源:互联网 发布:java byte转16进制 编辑:程序博客网 时间:2024/06/03 17:08
package sxt1102;
import java.io.*;
public class Test {


/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
File file = new File("c:/pan.txt");
File file2 = new File("c:/pan2.txt");
if(file.exists()){
try {
FileInputStream fileInputStream = new FileInputStream(file);
byte []b=new byte[(int) file.length()];
fileInputStream.read(b);
fileInputStream.close();
FileOutputStream fileOutputStream = new FileOutputStream(file2);
fileOutputStream.write(b);
fileOutputStream.close();
System.out.println("文件复制成功!");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


}
}


}
原创粉丝点击