Java Utililty Methods Path File Content

List of utility methods to do Path File Content

Description

The list of methods to do Path File Content are organized into topic(s).

Method

voidwriteToFile(Path absolutePath, byte[] content)
write To File
try (FileOutputStream fos = new FileOutputStream(absolutePath.toString())) {
    fos.write(content);
voidwriteToFile(Path file, String content)
Writes given string to a file.
Files.write(file, content.getBytes(CHARSET));
voidwriteToFile(Path path, String content)
write To File
Writer writer = null;
try {
    BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(path.toString()));
    writer = new OutputStreamWriter(outputStream);
    writer.write(content);
} finally {
    if (writer != null)
        writer.close();
...
voidwriteToFile(String content, String filePath)
write To File
Path path = Paths.get(filePath);
try {
    Files.write(path, content.getBytes("utf-8"));
} catch (UnsupportedEncodingException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
voidwriteToFile(String filePath, String content)
write To File
try {
    Files.write(Paths.get(filePath), content.getBytes());
} catch (IOException e) {
    e.printStackTrace();