Chapter 14 Cheatsheet
❗Important
PrintStreamclasses do not throw any checked exceptionsPathis an interfacePathsis a class (Paths has ansin it, so is class)
Method/Constructor to create a FileSystem
Using FileSystems
public static FileSystem getDefault()
➡️ FileSystem mySystem = FileSystems.getDefault();Method/Constructor to create a File
Using File
public File(String pathname)
➡️ File file1 = new File("/Users/username/IdeaProjects/ocpjava17/test.txt");
public File(File parent, string child)
➡️ File file2 = File(new File("/root/ocpjava17/test"), "test.java");
public File(String parent, String child)
➡️ File file3 = File("/root/ocpjava17", "test.java");Using Path
public default File toFile()
➡️ File file3 = File("/root/ocpjava17", "test.java");Method/Constructor to create a Path
Using FileSystem
public Path getPath(String first, String... more)Using File
public Path toPath()Using Path
public static Path of(String first, String... more)
public static Path get(URI uri)
public static Path get(String first, String... more)
public static Path get(URI uri)NIO.2 Path methods
public String toString()
public int getNameCount()
public Path getRoot()
public Path getParent()
public Path getFileName()
public Path getName(int index)
public Path resolve(String p)
public Path resolve(Path p)
public Path relativize(Path p)
public Path normalize()
public Path toRealPath()
public Path subpath(int beginIndex, int endIndex)NIO.2 optional parameters
LinkOption
LinkOption.NOFOLLOW_LINKS
StandardCopyOption
StandardCopyOption.ATOMIC_MOVEStandardCopyOption.COPY_ATTRIBUTESStandardCopyOption.REPLACE_EXISTING
StandardOpenOption
StandardOpenOption.APPENDStandardOpenOption.CREATEStandardOpenOption.CREATE_NEWStandardOpenOption.READStandardOpenOption.TRUNCATE_EXISTINGStandardOpenOption.WRITE
FileVisitOption
FileVisitOption.FOLLOW_LINKS
The java.io abstract stream base classes
InputStreamvsOutputStreamReadervsWriter
The java.io concrete I/O stream classes
Low level
FileInputStreamvsFileOutputStreamFileReadervsFileWriter
High level
BufferedInputStreamvsBufferedOutputStreamBufferedReadervsBufferedWriterObjectInputStreamvsObjectOutputStreamPrintStreamvsPrintWriter