/** * Converts hc.txt to hc.dat for hits count applet hc.class * @author Robert John Morton * @version 27 April 2000 */ // This program uses the Java 1.1.8 API. import java.io.*; class hctxtdat { public static void main(String args[]) throws IOException { BufferedReader // for reading the input text file r = new BufferedReader( new InputStreamReader( new FileInputStream("hc.txt") ) ); DataOutputStream // for writing the output data file w = new DataOutputStream( new FileOutputStream("hc.dat") ); String s; int x; /* While there are still more lines of text in the input file, read in the next line and get its length. */ while((s = r.readLine()) != null) { int l = s.length(); /* Provided this line contains more than 8 characters, it is a valid entry, so extract the number of hits for that week; otherwise, set it as a null entry. */ if(l > 8) x = Integer.parseInt(s.substring(8,l)); else x = -1; w.writeByte(x); // write the integer to the output data } // file as a single signed byte value w.close(); r.close(); } }