Answer:
pls mark my brainiest
Explanation:
Create an object of the File class
Pass it the name of the file to read in quotes
Then create an object of the Scanner class
Pass the constructor the new File object
Then use Scanner methods such as:
next()
nextLine()
hasNextLine()
hasNext()
nextDouble()
nextInt()...
File inputFile = new File("input.txt");
while (in.hasNextLine())
{
String line = in.nextLine();
// Process line;
}
Scanner in = new Scanner(inputFile);
Text File Output
Create an object of the PrintWriter class
Pass it the name of the file to write in quotes
• If output.txt exists, it will be emptied
• If output.txt does not exist, it will create an empty file
PrintWriter is an enhanced version of PrintStream
• System.out is a PrintStream object!
PrintWriter out = new PrintWriter("output.txt");
out.println("Hello, World!");
out.printf("Total: %8.2f\n", totalPrice);
System.out.println(“Hello World!”);
Then use PrintWriter methods such as:
print()
println()
p