Here you can find the source of writeFile(String fileName, String contents)
public static void writeFile(String fileName, String contents) throws IOException
//package com.java2s; //License from project: Apache License import com.amazonaws.util.StringInputStream; import java.io.*; public class Main { public static void writeFile(String fileName, String contents) throws IOException { writeFile(fileName, new StringInputStream(contents)); }/*from w ww .j a v a2s.c o m*/ public static void writeFile(String fileName, InputStream contents) throws IOException { OutputStream out; int read; byte[] bytes = new byte[1024]; final File file = new File(fileName); if (file.exists()) { file.delete(); } file.getParentFile().mkdirs(); file.createNewFile(); out = new FileOutputStream(file); while ((read = contents.read(bytes)) != -1) { out.write(bytes, 0, read); } out.flush(); out.close(); } public static boolean delete(String filePath) { return delete(new File(filePath)); } public static boolean delete(File file) { return file.exists() && file.delete(); } }