Here you can find the source of writeStringToFile(String text, String filePath)
public static boolean writeStringToFile(String text, String filePath)
//package com.java2s; import java.io.File; import java.io.FileOutputStream; import java.io.OutputStream; public class Main { public static boolean writeStringToFile(String text, String filePath) { OutputStream os = null;/* ww w . j ava 2 s . c o m*/ try { File file = new File(filePath); if (file.exists()) { file.delete(); } file.createNewFile(); os = new FileOutputStream(file); byte[] data = text.getBytes("UTF-8"); os.write(data); os.flush(); os.close(); return true; } catch (Exception e) { e.printStackTrace(); } finally { if (os != null) { try { os.close(); } catch (Exception e) { e.printStackTrace(); } } } return false; } }