📄✍️ Java Text I/O 💾🔍
In Java, Scanner reads input from the keyboard or from files (token-by-token using delimiters like whitespace), while PrintWriter writes text out to files cleanly. You’ll usually wrap file I/O in try-catch blocks to handle errors like missing files, and choose between approaches based on the job: Scanner is convenient for parsing numbers/words; PrintWriter is great for writing human-readable text; buffered streams are better for larger data or performance-sensitive work.
Common problems: FileNotFoundException happens when the path doesn’t exist or your program lacks permission.
With Scanner, delimiter and token issues are frequent—using nextInt() when the next token isn’t a number, or mixing
nextLine() with next()/nextInt() (newline leftovers). Java file paths can be relative to the
“working directory,” so "data/notes.txt" might work in an IDE but fail elsewhere unless the folder exists.
nextLine() calls.