Skip to main content

Student Portal > Contests > 

Programming Contest Central

   
Welcome students Resources Competition ProfilesFAQ
  Contest calendar
  Problem of the month
  Past problems
  Games and brainteasers
  Successes
  Tutorials

Input Output Files

import java.io.*;
/**
 * The following program demonstrates how you can read text from a
 * given file and print it into another file.
 */
public class InputOutputFile {
  public static void main(String[] args) throws IOException {
   

    // Reads from the file: C:\\readText.txt
    BufferedReader br = new BufferedReader(new FileReader("C:\\readText.txt"));
    // Prints to the file: C:\\printText.txt
    PrintStream ps = new PrintStream(new FileOutputStream("C:\\printText.txt"));
   
   
    // Reads from readText and prints all the lines into printText
    String line = br.readLine();
   
    while (line != null) {
      ps.println(line);
      line = br.readLine();
    }
  }
}



Back to top
 


Quick links

Student forum

Teacher resources

RSS Feed