I'm trying to create a java version of a UNIX script I have. In UNIX I can scan a file X, match a regexp pattern and then print the n^th word to the console (as defined by white spaces). With my java version, I have managed to pick my file using JFileChooser and read the file in as a string. I know the contents of the file have been read, because I can System.out.println and see the contents in the run window. This is what I have so far:
private void loadActionPerformed(java.awt.event.ActionEvent evt) {
try {
Scanner params = new Scanner (file_path);
while (params.hasNext()){
String test = params.nextLine();
System.out.println(test);
}
}
catch (Exception e) {
System.out.println("Error reading file");
}
and from here on I'm stuck. The file I'm reading looks like:
##FNAME = Foo ##SNAME = Bar ##AGE = 20 ##JOB = tobogganist
etc...
As an end result I would ideally like a string of "Foo" or whatever based upon a search pattern like "##FNAME = "
Sorry if this is utterly mundane, I've only recently started using java. I have tried googling, but I'm just getting lost in pattern, matcher, scanner, bufferedreader ....... and I can't get anything I try to work.
Thanks.

New Topic/Question
Reply



MultiQuote



|