Here you can find the source of saveFile(String pathname, String fileName, String contents)
public final static void saveFile(String pathname, String fileName, String contents) throws IOException
//package com.java2s; //License from project: Apache License import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; public class Main { public final static void saveFile(String pathname, String fileName, String contents) throws IOException { File filePath = new File(pathname); if (!filePath.exists()) filePath.mkdirs();/*www.j a va2 s . c o m*/ File file = new File(filePath, fileName); if (file.exists()) file.createNewFile(); OutputStream os = null; try { os = new BufferedOutputStream(new FileOutputStream(file)); os.write(contents.getBytes()); os.flush(); } catch (IOException e) { throw e; } finally { if (os != null) { os.close(); os = null; } } } }