本帖最后由 007lzg 于 2012-7-16 14:46 编辑
import java.io.*;
class CopyText
{
public static void main(String[] args) throws IOException
{
copy();
}
public static void copy()
{
FileWriter fw=null;
FileReader fr=null;
try
{
fw=new FileWriter("FileReaderDemo2_copy.txt");
fr=new FileReader("FileReaderDmeo2.java");
char[] buf=new char[1024];
int len=0;
while((len=fr.read(buf))!=-1)
{
fw.write(buf,0,len);
}
}
catch (IOException e)
{
throw new RuntimeException("读写有错误!");
}
finally
{
if(fr!=null)
try
{
fr.close();
}
catch (IOException e)
{
System.out.println(e.toString());
}
if(fw!=null)
try
{
fw.close();
}
catch (IOException e)
{
System.out.println(e.toString());
}
}
}
}
按照老师视频的步骤写的啊,为什么会有异常呢,能复制文件,但是文件是空的?
|
|