Class FilesApiExamples
java.lang.Object
net.jrodolfo.java_evolution.java11.FilesApiExamples
Demonstrates file convenience methods introduced in Java 11.
Before Java 11, reading or writing a whole text file often required byte arrays or extra charset-handling code. That was more ceremony than many simple text-file use cases needed.
Files.readString(Path) and
Files.writeString(Path, CharSequence, java.nio.file.OpenOption...)
solve the common whole-file text case directly.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReads text from a file usingFiles.readString(Path).voidWrites text to a file usingFiles.writeString(Path, CharSequence, java.nio.file.OpenOption...).
-
Constructor Details
-
FilesApiExamples
public FilesApiExamples()
-
-
Method Details
-
writeText
Writes text to a file usingFiles.writeString(Path, CharSequence, java.nio.file.OpenOption...).- Parameters:
path- the target pathcontent- the text to write- Throws:
IOException- when writing fails
-
readText
Reads text from a file usingFiles.readString(Path).- Parameters:
path- the source path- Returns:
- the file content
- Throws:
IOException- when reading fails
-