Here you can find the source of write(Path p, String s)
Parameter | Description |
---|---|
p | file destination (existing files will be overwritten) |
s | string to save |
Parameter | Description |
---|---|
IOException | if writing to file fails |
public static void write(Path p, String s) throws IOException
//package com.java2s; import java.io.BufferedWriter; import java.io.IOException; import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardOpenOption; public class Main { /**/*from w w w . j a v a 2 s . c o m*/ * Writes the specified string to a file. * * @param p * file destination (existing files will be overwritten) * @param s * string to save * * @throws IOException * if writing to file fails */ public static void write(Path p, String s) throws IOException { try (BufferedWriter writer = Files.newBufferedWriter(p, Charset.forName("UTF-8"), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) { writer.write(s, 0, s.length()); } } }