import java.io.*; class ReadWrite { public static void main(String args[]) throws IOException { String Names[] = new String[3]; int Ages[] = new int[3]; String line = new String(); int i; //openup file in FileReader FileReader file_input = new FileReader("data.txt"); //create BufferedReader from FileReader BufferedReader BR = new BufferedReader(file_input); //open output file FileOutputStream file_output = new FileOutputStream("reverse.txt"); DataOutputStream DOS = new DataOutputStream(file_output); //Read the 6 input lines of alternating Names and Age info for(i=0; i<3; i++) { Names[i] = BR.readLine(); line = BR.readLine(); Ages[i] = (Integer.valueOf(line)).intValue( ); //print info to screen and reverse order to output file System.out.println("Data" + i + " " + Names[i] + " " + Ages[i]); DOS.writeChars(line + " " + Names[i] + "\n"); } //Close streams BR.close(); file_input.close(); DOS.close(); file_output.close(); } } |