Java Path File Write nio writeToFile(Path path, String string)

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

Description

Writes the string to a file at the given path, overwriting any file present.

License

Open Source License

Parameter

Parameter Description
path the path to write to
string the string to write

Exception

Parameter Description
IOException if an error during writing occurs

Declaration

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

Method Source Code

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

import java.io.IOException;

import java.nio.charset.Charset;

import java.nio.file.Files;
import java.nio.file.Path;

import java.util.Collections;

public class Main {
    private static final Charset UTF8 = Charset.forName("UTF-8");

    /**//from   w w w.ja  va  2  s  .c o m
     * Writes the string to a file at the given path, overwriting any file present. Uses UTF-8.
     *
     * @param path the path to write to
     * @param string the string to write
     * @throws IOException if an error during writing occurs
     */
    public static void writeToFile(Path path, String string) throws IOException {
        Files.write(path, Collections.singletonList(string), UTF8);
    }
}

Related

  1. writeTagset(Path outPath, Set tagset)
  2. writeTestData(final String testdata, final Path tempfile)
  3. writeToFile(double[] testSample, Path classificationTestFile)
  4. writeToFile(final Path file, final String text)
  5. writeToFile(Path file, boolean isAppendingToFile, List lines)
  6. writeToFile(String log, Path path)
  7. writeToFile(String s, Path file)
  8. writeUntouchedImage(Path sourceFile, Path destFile)