SHARE
TWEET

Untitled

advictoriam Mar 12th, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.io.FileReader;
  2. import java.io.FileNotFoundException;
  3. import java.io.PrintWriter;
  4. import java.util.ArrayList;
  5. import java.util.Arrays;
  6. import java.util.Scanner;
  7. import java.util.Collections;
  8. import java.io.File;
  9.  
  10. public class LineReverser
  11. {
  12.    public static void main(String[] args)
  13.       throws FileNotFoundException
  14.    {
  15.       String inputFileName = "mary.txt";
  16.       String outputFileName = "output.txt";
  17.       String output = "";
  18.      
  19.       FileReader fr = new FileReader(inputFileName);
  20.       while(true)
  21.       {
  22.          try
  23.          {
  24.             int out = fr.read();
  25.             if(out == -1)
  26.                break;
  27.             output += (char)out;
  28.          }
  29.          catch(Exception e){}
  30.       }
  31.      
  32.       ArrayList<String>lines = new ArrayList<String>(Arrays.asList(output.split("\\r?\\n")));
  33.       Collections.reverse(lines);
  34.      
  35.       PrintWriter writer = new PrintWriter(new File(outputFileName));
  36.       for(int i = 0; i < lines.size(); i++)
  37.       {
  38.          writer.println(lines.get(i));
  39.       }
  40.       writer.close();
  41.    }
  42. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top