KickJava   Java API By Example, From Geeks To Geeks.

Java > Java SE, EE, ME > java > io > FileReader

java.io
Class FileReader

java.lang.Object
  extended by java.io.Reader
      extended by java.io.InputStreamReader
          extended by java.io.FileReader
All Implemented Interfaces:
Closeable, Readable
See Also:
Top Examples, Source Code, FileInputStream

public FileReader(File file)
           throws FileNotFoundException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public FileReader(FileDescriptor fd)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public FileReader(String fileName)
           throws FileNotFoundException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[161]Copy a file
By Anonymous on 2005/05/10 23:03:58  Rate
//Copy a file 
 try 
  {      
    String line = null; 
    BufferedReader br = new BufferedReader ( new FileReader ( "oldFileName" )  ) ; 
    PrintWriter pr = new PrintWriter ( new BufferedWriter ( new FileWriter ( "newFileName", false )  )  ) ;       
          
    while  (  ( line = br.readLine (  )  )  != null )   {  
         pr.println ( line ) ; 
     }  
   
    br.close (  ) ;             
    br = null; 
        
    pr.close (  ) ; 
    pr = null;         
        
  }  catch  ( java.io.FileNotFoundException ex )   {  
    System.out.println ( "File '" + args [ 0 ]  + "' does not exist. " ) ;       
  }  catch  ( java.io.IOException ex )   {  
    ex.printStackTrace (  ) ; 
  }  
 

Popular Tags