为什么我运行以后没有将FilewriterDemo.java文件复制到Test.txt中,抛出异常了?
- package com.day0;
- import java.io.*;
- import javax.management.RuntimeErrorException;
- public class FileCopy {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- }
- public void copy() throws IOException
- {
- FileWriter fw=null;
- FileReader fr=null;
- try
- {
- fw=new FileWriter("
- Test.txt
- ");
-
- fr=new FileReader("FilewriterDemo.java");
-
- char []buf=new char[1024];
-
- int len=0;
-
- while((len=fr.read(buf))!=-1){
-
- fw.write(buf);
- }
- }
-
- catch(IOException e){
-
- throw new RuntimeErrorException(null, "读写错误");
- }
-
- finally{
-
- if(fw!=null){
-
- fw.close();
- }
-
- if(fr!=null){
-
- fr.close();
- }
- }
- }
- }
复制代码
|
|