提示:Exception in thread "main" java.lang.IndexOutOfBoundsException
at sun.nio.cs.StreamEncoder.write(StreamEncoder.java:102)
at java.io.OutputStreamWriter.write(OutputStreamWriter.java:190)
at copyTest.copy_2(copyTest.java:23)
at copyTest.main(copyTest.java:9)
代码:
//文件的复制
import java.io.*;
class copyTest
{
public static void main(String[] args) throws IOException
{
copy_2();
}
public static void copy_2()
{
FileWriter fw=null;
FileReader fr=null;
try
{
fw=new FileWriter("F:\\zk-Dome\\copyof.txt");
fr=new FileReader("F:\\zk-Dome\\getSingleE.java");
char[] chs=new char[1024];
int len=0;
while ((len=fr.read())!=-1)
{
fw.write(chs,0,len);
}
}
catch (IOException e)
{
throw new RuntimeException("读写失败");
}
finally
{
if(fw!=null)
try
{
fw.close();
}
catch (IOException e)
{
throw new RuntimeException("写入失败");
}
if(fr!=null)
try
{
fr.close();
}
catch (IOException e)
{
throw new RuntimeException("读取失败");
}
}
}
}
|
|