import java.io.*;
class CopyText
{
public static void main(String[] args)
{
FileWriter fw=null;
FileReader fr=null;
try
{
fw= new FileWriter("D:\\demo.txt");
fr= new FileReader("C:\\FileWriterDemo.txt");
char[] buf=new char[1024];
int len=0;
while ((len=fr.read(buf))!=-1)
{
fw.write(buf,0,len);
}
}
catch (Exception e)
{
throw new RuntimeException("读写失败");
}
finally
{
try
{
if(fr!=null)
fr.close();
}
catch (Exception ex)
{
System.out.println(ex.toString());
}
try
{
if(fw!=null)
fw.close();
}
catch (Exception exc)
{
System.out.println(exc.toString());
}
}
}
}
|
|