Java files and I/O: streams, NIO.2 paths, text read/write

12 steps · about 3 h 52 min · Intermediate

  1. Lesson: Basic I/O (The Java Tutorials > Essential Java Classes) (doc, Oracle Java Tutorials, 10 min)

    The official map of the topic (streams, buffering, file I/O with NIO.2) so you know what you are about to learn.

  2. Javanotes 9, Section 11.1 -- I/O Streams, Readers, and Writers (guide, David J. Eck, Javanotes, 25 min)

    A gentle textbook introduction to why Java has byte streams for machine data and character streams for text.

  3. Character Stream Vs Byte Stream in Java (article, GeeksforGeeks, 12 min)

    Short side-by-side examples cement the naming pattern: InputStream and OutputStream for bytes, Reader and Writer for characters.

  4. Character Streams (The Java Tutorials) (doc, Oracle Java Tutorials, 15 min)

    Shows FileReader, FileWriter, BufferedReader and PrintWriter, the classic way to read and write text line by line.

  5. Character and Byte Streams (Internationalization) (doc, Oracle Java Tutorials, 10 min)

    Explains how InputStreamReader and OutputStreamWriter bridge bytes to characters with an explicit encoding such as UTF-8.

  6. I/O from the Command Line (The Java Tutorials) (doc, Oracle Java Tutorials, 10 min)

    System.in and System.out are streams too, so you can apply the same ideas to console input.

  7. Java I/O API tutorial (tutorial, dev.java (Oracle), 40 min)

    The current official tutorial, a bridge from the classic java.io classes to the modern NIO.2 Path and Files API.

  8. Reading and writing files in Java (Input/Output) - Tutorial (tutorial, vogella, 25 min)

    Practical one-liners with Files.readString, Files.lines and Files.write, plus an exercise to try yourself.

  9. How to use Java NIO API (article, ducmanhphan, 20 min)

    Covers building Paths and using newBufferedReader and newBufferedWriter, including the charset error you will hit on bad encodings.

  10. Working with files and directories in NIO.2 (article, Java Code Geeks, 20 min)

    Adds open options such as APPEND, plus copying, moving and mixing NIO.2 with streams.

  11. Java NIO and Advanced File Handling: Path, Files, FileChannel & WatchService (article, TutorialQ, 25 min)

    A current look at Java 11+ readString and writeString, then channels and memory mapping for larger files.

  12. Walking the File Tree (tutorial, dev.java (Oracle), 20 min)

    Finish by traversing whole directory trees, a common real-world use of NIO.2.