// read from file try{ BufferedReader bf = new BufferedReader(new FileReader(fname)); String s; while((s = bf.readLine()) != null){ Print.p(s); } bf.close(); }catch(IOException e){ } // write to file String fname = "/tmp/bst.txt"; try{ BufferedWriter bw = new BufferedWriter(new FileWriter(fname)); bw.write("123\n"); bw.close(); }catch(IOException io){ Print.p("Ex" + io.getMessage()); }