Reading text file
I have to read a text file, which the first line contains 2 numbers (integers) and then assign these to variables.
Here's the first few lines of the text file:
SEND 2228161 Hello Pete
RECEIVE 2228161 Hello Chris, how are you?
SEND 2227765 I hate text speak
RECEIVE 2228876 wot u on bout
SEND 2227975 The quick brown fox jumped over the lazy dog
Would I use the String.parseInt(value1) like this
sizeOfMessage = value1;
I then have to go on and read different String lines like SEND and RECEIVE
where I have used the if (line.startsWith("SEND")
Thanks for your help
You could try something like this (in pseudo code):
Scanner scanner = new Scanner(yourFile);
String line = scanner.nextLine();
String data = line.split("\\s");
// Check what we have here:
int sizeOfMessage = Integer.parseInt(data);
int sizeOfBox = Integer.parseInt(data);
// carry on reading...