Here you can find the source of writeFile(String filePath, Object obj)
public static void writeFile(String filePath, Object obj)
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.IOException; import java.io.FileOutputStream; public class Main { public static void writeFile(String filePath, Object obj) { FileOutputStream fop = null; File file;//from www .j av a 2 s. c om String content = obj.toString(); try { file = new File(filePath); fop = new FileOutputStream(file); // if file doesnt exists, then create it if (!file.exists()) { file.createNewFile(); } // get the content in bytes byte[] contentInBytes = content.getBytes(); fop.write(contentInBytes); fop.flush(); fop.close(); System.out.println("Data added to file " + filePath); } catch (IOException e) { e.printStackTrace(); } finally { try { if (fop != null) { fop.close(); } } catch (IOException e) { e.printStackTrace(); } } } }