• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

read text file into array

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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???
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic