/* * ========================================================================== * TestIOFile.java : This Java 2 program reads a stream of numbers from a * file stored locally on the same computer as the java program. * * Written By: Mark Austin February, 2006 * ========================================================================== */ import java.lang.Math; import java.util.*; import java.io.*; import java.text.*; import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class TestIOFile { public void readDataFile( String fileName ) throws IOException { int iNoDataItems = 0; String sName = null; String sLine; // Read triangle data from "triamgle.txt" FileReader inputFile = new FileReader( fileName ); BufferedReader in = new BufferedReader( inputFile ); try { // Get no of lines in input file .... sLine = in.readLine(); StringTokenizer st = new StringTokenizer(sLine); if ( st.hasMoreTokens() == true ) iNoDataItems = Integer.parseInt( st.nextToken() ); else System.out.println("*** ERROR in input file "); for ( int i = 1; i <= iNoDataItems; i = i + 1 ) { // Read name of item .... sLine = in.readLine(); StringTokenizer st1 = new StringTokenizer( sLine ); if ( st1.hasMoreTokens() == true ) { sName = st1.nextToken(); } // Read (x,y) coordinates of each node .... double dX1 = Double.parseDouble( st1.nextToken() ); double dY1 = Double.parseDouble( st1.nextToken() ); // Read data point status .... boolean bActivePoint; if ( st1.nextToken().equals("false") == true ) bActivePoint = false; else bActivePoint = true; // Echo output .... System.out.print("Name( " + sName + " ):"); System.out.print("(x,y) =" + "(" + dX1 + "," + dY1 + "): "); System.out.println("Pole Status = " + bActivePoint ); } } catch (FileNotFoundException e){} catch (EOFException e){} /// Close input file in.close(); } // Exercise methods in TestIOFile() .... public static void main( String args[] ) throws IOException { // Create object for test IO program.... TestIOFile tio = new TestIOFile(); // Read content from data.txt .... tio.readDataFile( "data.txt" ); } }