• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading words from a file

 
Jay Dilla
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to read lines in a file word by word and spit it back out with something appended to it.
I know I can use Scanner to read lines, but there is not Scanner method to parse strings from the line. Is it possible to Scan lines in a loop then parse the words from the line in another loop?
What's the best method to implement this?
 
Nicholas Jordan
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well definitely yes, it is a standard cs exercise; but please give some idea of what the string looks like you want to parse and what splitting chars may be available to split the string on and so on. It is all very straight forward, just provide some more details so that we do not begin guessing and give time-wasting blunders to your effort.
 
Rob Spoor
Sheriff
Pie
Posts: 20753
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I haven't really worked with it, but you could look at java.text.BreakIterator. It has a static method getWordInstance() that returns a BreakIterator that might be useful for you.
 
Jay Dilla
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are multiple words in the file , some on different lines.
For instance
The only delimiter would be space between each word. How would I find out if i'm at the end of a line and how do i write it into another file exactly like that , but with the ability to append things in between each word if i want.
 
Nicholas Jordan
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I patched together the following in the hopes of pulling some more program specifications.
A wish list would do just fine, even random thoughts or a plain:

"I have not thought about that."

You would really be suprised how many development paths this program can take, and in fact I will probably use the above short snippet in my program.

Use StringBuffer or StringBuilder to insert words into a line of text. readline returns a String, which will not let you insert characters in it.

[ Message edit: See the topic: each cutomer have multiple records ,they are identified by their calling number it is a few steps ahead of where your question is, but is the same question - also note my code has errors in it and you are supposed to read the code for ideas, not blindly template your work from the code ]
[ November 13, 2007: Message edited by: Nicholas Jordan ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic