编程题:请读取文件内容并将内容填写到一个新文件里面。
文件目录:d://abc.txt
新文件目录:d://abd.txt
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class A10 {
public static void main(String[] args) {
FileInputStream input = null ;
FileOutputStream out = null ;
try {
File f = new File("E:\\1\\AGT_ENROL");
input = new FileInputStream(f);
out = new FileOutputStream("E:\\1\\AGT.txt");
byte[] bytes = new byte[(int) f.length()]; // 一次读取多少字节文件
int temp = 0;
while((temp = input.read(bytes))!=-1){ // -1为文件读完的标志
out.write(bytes, 0, temp);
}
out.flush();
} catch (Exception e) {
e.printStackTrace();
} finally{
if(input != null){
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if(out != null){
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}