public class TxtWrite { public static void main(String args[]){ contentToTxt("D:\xyky.txt","3"); } public static void contentToTxt(String filePath, String content) { try{ BufferedWriter writer = new BufferedWriter(new FileWriter(new File(filePath),true)); writer.write(" "+content); writer.close(); }catch(Exception e){ e.printStackTrace(); } } }