> If this is an exercise, the teacher should give you a grammar for the
> language of the source file.
[quoted text clipped - 4 lines]
> One can not write a scanner or a parser for a language that is not
> specified.
By grammar, this is where things are headed:
firstName = "Brenda";
lastName = "Lee";
but maybe I'm not using Scanner correctly because guests.get(0) is the
whole line, whereas I expected useDelimiter() to break it into smaller
pieces based on using a comma as the delimiter. I'll re-read the Sun
tutorial, http://java.sun.com/docs/books/tutorial/essential/io/
scanning.html, but that's what I thought they were doing.
thufir@arrakis:~/bcit-comp2611-lab4$
thufir@arrakis:~/bcit-comp2611-lab4$ cat src/a00720398/labs/Lab4.java
/**
* Lab4.java
*/
package a00720398.labs;
import java.util.*;
import java.io.*;
import java.util.ArrayList;
import a00720398.util.*;
import a00720398.data.*;
public class Lab4 {
public static void main (String[] args) {
// scan();
// }
// public static void scan(){
Scanner s = null;
ArrayList<String> guests = new ArrayList<String>();
try {
//Scanner s = new Scanner(input).useDelimiter("\
\s*fish\\s*");
s = new Scanner(new BufferedReader(new FileReader
("guests.txt"))).useDelimiter("/,");
while (s.hasNext()) {
String guest = s.next();
guests.add(guest);
}
} catch (IOException e) {
System.out.println(e.getMessage());
e.printStackTrace();
} finally {
if (s != null) {
s.close();
}
}
System.out.println(guests.get(0));
}
}
thufir@arrakis:~/bcit-comp2611-lab4$
thanks,
Thufir
thufir - 08 May 2008 02:15 GMT
> but maybe I'm not using Scanner correctly because guests.get(0) is the
> whole line, whereas I expected useDelimiter() to break it into smaller
> pieces based on using a comma as the delimiter. I'll re-read the Sun
> tutorial, http://java.sun.com/docs/books/tutorial/essential/io/
> scanning.html, but that's what I thought they were doing.
Well, the example at http://www.kodejava.org/examples/242.html solved my
problems. I'm not quite sure *why*, but it looks like they're
differentiating lines.
-Thufir
Roedy Green - 08 May 2008 20:26 GMT
>firstName = "Brenda";
that is not what is usually meant by CSV. That looks more like a
subset of Java.
see http://mindprod.com/jgloss/csv.html
http://mindprod.com/jgloss/parser.html

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com