PDA

View Full Version : parsing a file in java



Mia_tech
March 29th, 2009, 08:25 AM
guys, using the Scanner for reading files how could I parse the question from the answer

Which of the following types are supertypes of Rectangle?
A) PrintStream
B) Shape
C) RectangularShape
D) Object
E) String
Select all that apply:
BCD


FileReader file = new FileReader("quiz.txt");
Scanner in = new Scanner(file);
//calling the method that reads the file
q.read(in);


now the read method who parses questions from answers


public void read(Scanner in) throws IOException
{
boolean done = false;
while(!done)
{
//code here
addQuestions(new Question(question, answer);
}
}

I'm having a bit of difficulty working with the scanner, so far I've always done it with a BufferedReader

simeon87
March 29th, 2009, 12:55 PM
Did you search for examples? Just Googling for 'java scanner example' gives me: http://www.java-tips.org/java-se-tips/java.util/scanning-text-with-java.util.scanner-3.html

Mia_tech
March 29th, 2009, 07:32 PM
Did you search for examples? Just Googling for 'java scanner example' gives me: http://www.java-tips.org/java-se-tips/java.util/scanning-text-with-java.util.scanner-3.html

If I don't google is b/c sometimes either don't have the time or I'm involve in other project... so if all you going to do is post a link save your time... not interested

simeon87
March 29th, 2009, 08:21 PM
If I don't google is b/c sometimes either don't have the time or I'm involve in other project... so if all you going to do is post a link save your time... not interested

If that's all you can say, why should we/I spend our/my time explaining how the Scanner class works?

Googling a few words takes zero effort and should be the first step because others have often tackled the same problem. In particular with something as common as the Scanner class.

Edit: to be clear: the link I mentioned fully answers your questions on how to do this - there's a wealth of information already on the web, so it's up to you if you're willing to use it.

Can+~
March 29th, 2009, 09:05 PM
If I don't google is b/c sometimes either don't have the time or I'm involve in other project... so if all you going to do is post a link save your time... not interested

So you had the time to post in a forum, but not the time to do a google search?

Sheesh.