这是我编的一个文件拷贝的程序,为什么文件读入正确,创建新文件也成功了,却没有在新文件中写入任何东西?
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.FileWriter;
import java.io.BufferedWriter;
public class MyCopy
{
public static void main(String[] args)
{
try
{
String source = args[0];
String object = args[1];
FileReader fr = new FileReader(source);
BufferedReader br = new BufferedReader(fr);
FileWriter fw = new FileWriter(object);
BufferedWriter bw = new BufferedWriter(fw);
String temp = br.readLine();
while (temp != null)
{
System.out.println(temp);
bw.write(temp);
bw.newLine();
temp = br.readLine();
}
br.close();
fw.close();
fr.close();
}
catch (IOException e)
{
System.out.println("文件不存在!");
}
System.out.println("文件复制成功!");
}
}