Here you can find the source of writeToFile(Path path, String string)
Parameter | Description |
---|---|
path | the path to write to |
string | the string to write |
Parameter | Description |
---|---|
IOException | if an error during writing occurs |
public static void writeToFile(Path path, String string) throws IOException
//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); } }