Here you can find the source of add2File(String fileName, String content)
public static int add2File(String fileName, String content)
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.FileWriter; import java.io.IOException; public class Main { public static int add2File(String fileName, String content) { File file = new File(fileName); try {//from w ww . j av a2s .c om // if the file is not exist, create it! if (file.exists() == false) { file.createNewFile(); } // the second parameter is 'true' means add contents at the end of // the file FileWriter writer = new FileWriter(fileName, true); writer.write(content); writer.close(); return 1; } catch (IOException e) { e.printStackTrace(); return 0; } } }