Java Path File Content writeToFile(Path path, String content)

Here you can find the source of writeToFile(Path path, String content)

Description

write To File

License

Open Source License

Declaration

public static void writeToFile(Path path, String content) throws FileNotFoundException, IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.BufferedOutputStream;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

import java.io.Writer;

import java.nio.file.Path;

public class Main {
    public static void writeToFile(Path path, String content) throws FileNotFoundException, IOException {
        Writer writer = null;//from  w  w  w  .  j  a  v a  2s.co  m

        try {
            BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(path.toString()));
            writer = new OutputStreamWriter(outputStream);
            writer.write(content);
        } finally {
            if (writer != null)
                writer.close();
        }
    }
}

Related

  1. writeString(String content, Path path)
  2. writeStringToFile(String content, Path targetPath)
  3. writeToBinaryFile(String filePath, byte[] binaryContent)
  4. writeToFile(Path absolutePath, byte[] content)
  5. writeToFile(Path file, String content)
  6. writeToFile(String content, String filePath)
  7. writeToFile(String filePath, String content)