Programs that only use console I/O are limited. Real applications read configuration files, process CSVs, and write logs. Java handles all of this through the java.io and java.nio packages.
Here is how you read a text file line by line:
BufferedReader reader = new BufferedReader(new FileReader("data.txt"));
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
reader.close();
And here is how you write to a file:
BufferedWriter writer = new BufferedWriter(new FileWriter("output.txt"));
writer.write("Hello from Java");
writer.newLine();
writer.close();
If you forget to call close(), data might not get written to disk. A try-with-resources block closes the stream automatically when the block ends.