The Artima Developer Community
Sponsored Link

Java Answers Forum
Reading file input

4 replies on 1 page. Most recent reply: Feb 11, 2004 5:55 AM by Niall

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 4 replies on 1 page
Niall

Posts: 10
Nickname: niall
Registered: Feb, 2004

Reading file input Posted: Feb 6, 2004 12:46 PM
Reply to this message Reply
Advertisement
I am trying to read in a file in the following format:
A B C ; AB9 BC6
Currently I can read in the file using the StringTokenizer and store each element in a vector v1. My problem is that after the ; (this could be any value) I want to store the remaining values in another vector v2.

I would be very grateful if anyone could help me with this prolem.


Senthoorkumaran Punniamoorthy

Posts: 335
Nickname: senthoor
Registered: Mar, 2002

Re: Reading file input Posted: Feb 6, 2004 3:13 PM
Reply to this message Reply
Ok What is the current problem with using ";" as a token and then storing the value before the token in vector v1 and the value after ; in vector v2? If the code you have written already for this is not working please post the code!

Niall

Posts: 10
Nickname: niall
Registered: Feb, 2004

Re: Reading file input Posted: Feb 7, 2004 10:31 AM
Reply to this message Reply
This is my code so far:

String vText;
String lineRead="";
BufferedReader br = new BufferedReader(new FileReader(infile));
while ((lineRead = br.readLine()) != null)
{ vText = lineRead;
StringTokenizer tokenizer = new StringTokenizer(vText);
while (tokenizer.hasMoreTokens())
{
String token = tokenizer.nextToken();
V1.addElement(token);
}
}
[pre]
This adds all elements in the input file described above
to the vector V1. However I want to just add the elements
up to the ; to V1, then the rest into a different vector V2

aj3423 aj

Posts: 16
Nickname: aj3423
Registered: Aug, 2003

Re: Reading file input Posted: Feb 11, 2004 12:01 AM
Reply to this message Reply
look up all the ";" first, then create a new Vector[] like this:
Vector[] v = new Vector[number of ";"]
then:

int i = 0;
while(tokenizer.hasMoreTokens()) {
String token = tokenizer.nextToken();
if(token.equals(";") {
i++;
} else {
V.addElement(token);
}
}

hope it helps.

Niall

Posts: 10
Nickname: niall
Registered: Feb, 2004

Re: Reading file input Posted: Feb 11, 2004 5:55 AM
Reply to this message Reply
Thanks for the help aj, got it working now.

Cheers.

Flat View: This topic has 4 replies on 1 page
Topic: cannot resolve symbol problem Previous Topic   Next Topic Topic: Conversion of class file into executable format.

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use