Exercise
Appending To A Text File
Objetive
Create a program to ask the user for several sentences (until they just press Enter) and store them in a text file named "sentences.txt". If the file exists, the new content must be appended to its end.
Example Code
import java.util.*;
public class Main
{
public static void main(String[] args)
{
java.io.OutputStreamWriter myFile = File.AppendText("file.txt");
String line;
do
{
System.out.print("Enter a sentence: ");
line = new Scanner(System.in).nextLine();
if (!line.equals(""))
{
myFile.write(line + System.lineSeparator());
}
} while (!line.equals(""));
myFile.close();
}
}