new PrintWriter(Writer out) : PrintWriter « java.io « Java by API






new PrintWriter(Writer out)

 
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;

public class Main {

  public static void main(String[] args) {
    try {
      BufferedReader input = new BufferedReader(new FileReader(args[0]));
      ArrayList list = new ArrayList();
      String line;
      while ((line = input.readLine()) != null) {
        list.add(line);
      }
      input.close();

      Collections.reverse(list);

      PrintWriter output = new PrintWriter(new BufferedWriter(new FileWriter(args[1])));
      for (Iterator i = list.iterator(); i.hasNext();) {
        output.println((String) i.next());
      }
      output.close();
    } catch (IOException e) {
      System.err.println(e);
    }
  }
}

   
  








Related examples in the same category

1.new PipedWriter()
2.new PrintWriter(BufferedWriter, boolean autoFlush)
3.PrintWriter: close()
4.PrintWriter: print(char c)
5.PrintWriter: print(int i)
6.PrintWriter: println(Object x)
7.PrintWriter: println(String x)
8.PrintWriter: println(char x)
9.PrintWriter: println(double x)
10.PrintWriter: println(float x)
11.PrintWriter: println(int x)
12.PrintWriter: println(long x)
13.PrintWriter: println()
14.Writer: write(char[] cbuf)