- import java.io.*;
- class CopyText
- {
- public static void main(String[] args)
- {
- copy_2();
- }
- public static void copy_2(){
- FileReader fr = null;
- FileWriter fw = null;
-
- try
- {
- fr = new FileReader("11.txt");
- fw = new FileWriter("22.txt");
- char[] arr = new char[1024];
- int len = 0;
- while((len = fr.read(arr))!=-1){
- fw.write(arr,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());
- }
- }
- }
- }
- /*
- public static void copy_1()throws IOException{
- FileReader fr = new FileReader("11.txt");
- FileWriter fw = new FileWriter("22.txt");
- int ch = 0;
- while((ch = fr.read())!=-1){
- fw.write(ch);
- }
- fr.close();
- fw.close();
- */
- }
- }
复制代码
在copy_2 方法中。。为什么在if判断是 不等于null。。应该是等于null才对呀。。 |
|