import java.io.*;class FileDemo { public static void main(String[] args) throws IOException{ String path = "d://demo//1.txt"; File f =new File(path); f.createNewFile(); if(f.exists()) System.out.PRintln("exists"); String str = "hello"; FileWriter fw = null; fw = new FileWriter(path, true); //if true, then bytes will be written to the end of the file rather than the beginning fw.write(str); fw.flush();//Flushes the stream. fw.close(); StringBuilder build = new StringBuilder(); FileReader reader = new FileReader(path); int ch; while((ch = reader.read())!= -1){ build.append((char)ch); } String str2 = build.toString(); System.out.println(str2); } }