JohnPhilipps 16 Junior Poster in Training

Good morning,

I am quite new at java and in the learning process.

I have a log file with the following data contained in it:
mai 4 03:26:53 pcjournal Dock[345]: Corrupt JPEG data: premature end of data segment
mai 4 03:26:53 pcbookscuba [0x1-0xa01a].com.apple.dock[345]: Tue Jun 2 03:26:53 macbookscuba.local Dock[215] <Error>: Corrupt JPEG data: premature end of data segment

I would like to read my text file and parse it and print out statistics for number of messages per minute, number of messages per hour, number of messages per day.

I am thinking of using arraylist to hold the data, perhaps a list of arraylist to hold each line I'm not sure.

So far I can read the text file holding the data:

import java.io.*; 

  class FileReadTest { 

     public static void main (String[] args) { 
	FileReadTest f = new FileReadTest();
        f.readMyFile(); 
     } 

     @SuppressWarnings("deprecation")
	void readMyFile() { 

        DataInputStream dis = null; 
        String record = null; 
        int recCount = 0; 

        try { 

           File f = new File("mydata.txt"); 
           FileInputStream fis = new FileInputStream(f); 
           BufferedInputStream bis = new BufferedInputStream(fis); 
           dis = new DataInputStream(bis);  

           while ( (record=dis.readLine()) != null ) { 
              recCount++; 
              System.out.println(recCount + ": " + record); 
           } 

        } catch (IOException e) { 
           // catch io errors from FileInputStream or readLine() 
           System.out.println("IOException error!" + e.getMessage()); 

        } finally { 
           // if the file opened okay, make sure we close it 
           if (dis != null) { 
	      try {
                 dis.close(); 
	      } catch (IOException ioe) {
	      }
           } 
        } …
VernonDozier commented: Thanks for using code tags on your first post. +16