Question: I have to write code that will reverse the order of the string and write it in a new file. For example :

Hi my name is Bob.

I am ten years old.

The reversed will be :

I am ten years old.

Hi my name is Bob.

This is what I have so far. Not sure what to write for the outWriter print statement. Any help will be appreciated. Thanks!

```
import java.io.*;
import java.util.ArrayList;
import java.util.Scanner;
public class FileRewinder {
    public static void main(String[] args) {
        File inputFile = new File("ascii.txt");

        ArrayList<String> list1 = new ArrayList<String>();
        Scanner inputScanner;
        try {
        inputScanner = new Scanner(inputFile);
        } catch (FileNotFoundException f) {
            System.out.println("File not found :" + f);
            return;
        }
        while (inputScanner.hasNextLine()) {
            String curLine = inputScanner .nextLine();

            System.out.println(curLine );
        }
        inputScanner.close();
    File outputFile = new File("hi.txt");
    PrintWriter outWriter = null;
    try {
        outWriter = new PrintWriter(outputFile);
    } catch (FileNotFoundException e) {
        System.out.println("File not found :" + e);
        return;
    }
    outWriter.println(???);

    outWriter.close();

    }
}

```

Answer: 
My suggestion is read entire file first and store sentences(you can split by `.`) in a `LinkedList<String>`(this will keep insertion order)

Then use `Iterator` and get sentences in reverse order. and write them into a file. make sure to put `.` just after each sentence.
After `System.out.println(curLine );` add `list1.add(curline);` that will place your lines of text into your list.

At the end create a loop over `list1` backwards:

```
for(int i = list1.size() - 1 , i > 0, --i) {
     outWriter.println(list1[i]);
}

```