Class FileWriter Class FileRead

解决方案 »

  1.   

    /*
        Example based on Sun Java I/O tutorial for File Streams
        
        Reads in a file and copies it out to another file.
     */
     
     import java.io.*;  public class Copy {
          public static void main(String[] args) throws IOException {
              // create two file references
              File inputFile = new File("jung.txt");
              File outputFile = new File("jungout.txt");          // create two File Streams
              FileReader in = new FileReader(inputFile);
              FileWriter out = new FileWriter(outputFile);
              
              // read one file and write it out to another
              int c;          while ((c = in.read()) != -1)
                 out.write(c);          // close both files
              in.close();
              out.close();
          }
      }