import java.io.*; class TextProcessor { private FileWriter fw; private PrintWriter pw; private File textFile; private FileReader fr; private BufferedReader br; private String[] books = { "Rhetorica", "Against the wind", "author unkowns", "Deerslayer"}; public TextProcessor() { try { textFile = new File("d:/temp/books.txt"); fw = new FileWriter(textFile); pw = new PrintWriter(fw); } catch(IOException e) { System.out.println("cannot create file: " + e.toString()); } } public void writeOutput() { for(int i=0; i<3; i++) { pw.println(books[i]); } pw.flush(); pw.close(); } public void readInput() { try { fr = new FileReader(textFile); br = new BufferedReader(fr); do { String line = br.readLine(); System.out.println(line); }while(br.ready()); } catch(IOException e) { System.out.println("read failed: " + e.toString()); } } } public class fio { public static void main(String args[]) { TextProcessor textP = new TextProcessor(); textP.writeOutput(); textP.readInput(); System.exit(0); } }