Java examples for File Path IO:File Operation
Save String to a file by converting the text to a byte array
import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; public class Main { public static void main(String[] args) { Path rf_wiki_path = Paths.get("C:/folder1/wiki", "wiki.txt"); String rf_wiki = "this is a test"; try {/*w w w. j a v a 2 s .co m*/ byte[] rf_wiki_byte = rf_wiki.getBytes("UTF-8"); Files.write(rf_wiki_path, rf_wiki_byte); } catch (IOException e) { System.err.println(e); } } }