Scanner sc = null; PrintWriter fileOut = null; try { // // Set up the input file to be read // sc = new Scanner(new File(args[0])); } catch(Exception e0) { System.err.println("Input file "+args[0]+" is not accessible"); System.exit(0); } try { // // Set up the output file fileOut = new PrintWriter(new BufferedWriter(new FileWriter(args[1]))); } catch(Exception e1) { System.err.println("Output file "+args[1]+" is not accessible"); System.exit(1); } // // Read the first line of the .dat file. We want to store the // "sample rate" in a variable, but we can ignore the rest // of the line. We step through the first line one token (word) // at a time using the Scanner. The fourth token // is the one we want (the sample rate). // Double sampleRate; sc.next(); // Read in semicolon sc.next(); // Read in "Sample" sc.next(); // Read in "Rate" sampleRate = sc.nextDouble(); // Read in sample rate // // Read in the file and place values from the second column // in the stack. The first column values are thrown away. // We stop reading if we reach the end of the file. // Lines begininning with semicolon are discarded // Stack s = new Stack(); double timestep, data; int count = 0; try { if (sc.next(";")!=null) sc.nextLine(); // Skip lines starting with semicolon } catch(Exception e2) {} while (sc.hasNext()) { timestep = sc.nextDouble(); // Read in time step value from first column // -- which we do not need data = sc.nextDouble(); // Read in data value from second column // -- which we *do* need s.push(data); count++; } System.out.println(count+" samples in file");