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

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

Description

Writes given string to a file.

License

Open Source License

Declaration

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

Method Source Code


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

import java.io.IOException;
import java.nio.file.Files;

import java.nio.file.Path;

public class Main {
    private static final String CHARSET = "UTF-8";

    /**/*w w w .j av a  2 s  .  co m*/
     * Writes given string to a file.
     * Will create the file if it does not exist yet.
     */
    public static void writeToFile(Path file, String content) throws IOException {
        Files.write(file, content.getBytes(CHARSET));
    }
}

Related

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