wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes read text file into array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "read text file into array" Watch "read text file into array" New topic
Author

read text file into array

haijun wang
Greenhorn

Joined: Aug 18, 2000
Posts: 21
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

Joined: Sep 29, 2000
Posts: 8521
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???


"JavaRanch, where the deer and the Certified play" - David O'Meara
 
wood burning stoves
 
subject: read text file into array
 
Similar Threads
B&S Parsing of Data file
DataInputStream Help needed while creating file
calling an external file
Error loading object from file in JasperReport Can any one Help...
read a text file