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) {
}
}
}
}
}
The problem I am having is that I do not know how to go about obtaining the result I am looking for.
Could somebody guide me in the right direction? Perhaps a tutorial or an example I could work with.
THank you very much for your help,
John