Here you can find the source of writeFile(String fileName, String content)
public static void writeFile(String fileName, String content) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.*; import java.nio.charset.StandardCharsets; public class Main { public static void writeFile(String fileName, String content) throws IOException { writeFile(fileName, new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8))); }//from w ww. ja va2 s.co m public static void writeFile(String fileName, InputStream content) throws IOException { writeFile(new File(fileName), content); } public static void writeFile(File file, String content) throws IOException { writeFile(file, new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8))); } public static void writeFile(File file, InputStream content) throws IOException { if (content == null) { throw new IllegalArgumentException("content must not be null"); } if (!file.exists()) { file.createNewFile(); } FileOutputStream stream = new FileOutputStream(file); byte[] buffer = new byte[1024]; int length; while ((length = content.read(buffer)) != -1) { stream.write(buffer, 0, length); } stream.close(); } }