Guided Notes

Files & I/O

Creating, writing, reading, and deleting files with File, FileWriter, Scanner, and BufferedReader/Writer.

The File class

Slide 1 / 5

java.io.File represents a path to a file or folder:

File file = new File("notes.txt"); file.exists() β†’ true or false file.getName(), file.getAbsolutePath() file.length() β†’ size in bytes file.createNewFile() β†’ true if it was created file.delete() β†’ true if it was deleted

Most file operations throw IOException, a checked exception, so they must be inside try/catch or in a method declared with throws IOException.

← Exceptions & Debugging