Hello guys I need a little help(I think). So i start work with TxT files. And i need know how to write text in the next line if file exist. My code just last text replace new.. Here code :
Main :
package YoYo; import java.util.Scanner; public class Main { static String atsakymas; static String FileName; static Scanner kl = new Scanner(System.in); static Scanner kl2 = new Scanner(System.in); static Creating create = new Creating(); public static void main(String[]args) { String irasyti = grazina(); System.out.println("Please enter file name"); FileName = kl.nextLine(); create.createFile(FileName,irasyti); create.closeFile(); } static String grazina() { String irasyti = null; System.out.println("Are you want write something in file?"); atsakymas = kl2.nextLine(); if (atsakymas.equals("Yes")) { System.out.println("What you want write?"); irasyti = kl.nextLine(); System.out.println(irasyti); } return irasyti; } }
Creating:
package YoYo; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.io.UnsupportedEncodingException; import java.util.Formatter; public class Creating { PrintWriter x; String file; String WhatWrite; public void createFile(String filename, String writing) { file = filename; WhatWrite = writing; try { x = new PrintWriter(file); x.println(WhatWrite); } catch(Exception e) { System.out.println("Error"); } } public void closeFile() { x.close(); } }
Sorry for bad English