• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • fred rosenberger
  • salvin francis

BufferedReader & StringTokenizer

 
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've read in lines from a text file before without any difficulties. However the text file i'm reading now has alot of semicolons, periods etc..
So I use a delimiter with alot of parameters. The problem is that the following code doesn't read in the entire text file, it starts about 200 lines down and goes right to the end. Even if I get rid of the delimiter, it doesn't start at the beginning of the file...Can anyone help me out with my code?

 
Ranch Hand
Posts: 621
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok,
well i think it will be better if you use the "split method "of String class instead of using the String Tokenizer.Below shown is the link where you will find the description of split method and the way you can use it.

http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html

I hope if it helps you.
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
John,

If I've understood your description correctly (at this late hour), I think your program does just what you were expecting it to do, provided a few additional pieces are included.

When posting the example code, I'm guessing you maybe left out the pieces where you print or otherwise use the tokens read in.

For the following code example, I copied and pasted your code, and then I added a couple of lines that print the input data (in "raw" and "tokenized" fashions). I think it does what you want it to do. (Below, I'll also paste the "input.txt" file I tested with.)

To otherwise guess at what ailment is plaguing you... Do you perhaps have a development environment problem, where maybe an old version of your program code is mistakenly being run, or where maybe an old version of the input data is mistakenly being used?

Foo.java


input.txt


output
 
John Lockheart
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the code works too. I think the problem is, is that my text file being read contains ALOT of lines and words. After further testing of my program I see that it is indeed processing all the lines and words properly. However, I still don't understand why they don't print to screen properly when I try and print the tokens or lines. It always starts at line, let's say 300 and prints out the results. When indeed it is processing previous lines. Very strange! Thanks for the help though!
 
Marshal
Posts: 26697
81
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't see anywhere in the code you originally posted where you write anything out anywhere. However let's suppose you actually have some code like what Dirk posted, and you're just writing the tokens out to the console.

Then, if you can't see the beginning of your output, it probably just scrolled off the top of the console window.
 
John Lockheart
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nope, scrolled to the top of the console window and found it started at a later line. That's why I assumed it wasn't starting from the beginning...
 
Paul Clapham
Marshal
Posts: 26697
81
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The console window probably threw away the first 300 lines.

But let's not waste time speculating, especially since I have no idea what kind of console you're using. Write your output to a file instead and see what happens.
 
The moustache of a titan! The ad of a flea:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic