You might try the following approach (filling the gaps, see the
TODO remarks)
package a3;
import java.io.FileWriter;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;
import java.util.ArrayList;
public class A3
{
public static void main(String[] args) throws IOException
{
{
FileWriter input = new FileWriter("input.txt");
input.write("Mary had a little lamb \n");
input.write("Its fleece was white as snow. \n");
input.write("And everywhere that Mary went. \n");
input.write("The lamb was sure to go. \n");
input.close();
}
{
FileReader input = new FileReader("input.txt");
Scanner sc = new Scanner(input);
while ( sc.hasNextLine() )
{
System.out.println(sc.nextLine());
}
}
}
}