Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

read text file into array

 
haijun wang
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Friends:
I have your help for read two text files into two different string arrays in order for me find the the words, which exist in one text file, also in other text file.
Haijun
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which part do you need help with??
If you use a String array, you will probably end up with duplicate words in the arrays. That would give you the same results on the compare each time. Perhaps using a Set or a Sorted set would be better, and just discard words that you have already loaded.
You need to have 2 FileInputStreams (then you should run those through 2 DataInputStreams) then read the first file, one character at a time (using readChar()) appending the character onto a variable String - probably until you run into a space (that would be the end of the word). Then take the variable and load it into the first array at index 0, and clear the variable. Keep going until all of the words of the first file are loaded.
You could probably start reading the second file in the same manner until you find the first word, and stop and search the first array for that word right then. If you find a match, load the match into the second array.
Is this sort of what you need to do???
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic