Here you can find the source of writeToFile(final File file, final String data)
public static void writeToFile(final File file, final String data) throws IOException
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; public class Main { /**/*from w w w . j av a 2 s . c om*/ * Write a UTF-8 string to a file object. */ public static void writeToFile(final File file, final String data) throws IOException { writeToFile(file.toPath(), data); } /** * Write a UTF-8 string to a path string. */ public static void writeToFile(final String path, final String data) throws IOException { writeToFile(Paths.get(path), data); } /** * Write a UTF-8 string to a path object. */ public static void writeToFile(final Path path, final String data) throws IOException { writeToFile(path, data.getBytes(StandardCharsets.UTF_8)); } /** * Write bytes to a file object. */ public static void writeToFile(final File file, final byte[] data) throws IOException { writeToFile(file.toPath(), data); } /** * Write bytes to a path string. */ public static void writeToFile(final String path, final byte[] data) throws IOException { writeToFile(Paths.get(path), data); } /** * Write bytes to a path object. */ public static void writeToFile(final Path path, final byte[] data) throws IOException { Files.write(path, data); } }