This week's giveaway is in the Spring forum.
We're giving away four copies of Learn Spring Security (video course) and have Eugen Paraschiv on-line!
See this thread for details.
Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Comparing contents of a file with String[]

 
Eduardo Ponce de Leon
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am trying to compare the contents of an array to what ever there is in a file...so that
if - whatever i have in array[i] is in file
DO SOMETHING
else
DO SOMETHING

as of now i take the first element of my array and check it agains my file, however, when i find a match in my file i dont know how to reset my Buffer reader to start reading from the top of the file again and to check the next element in my array...here is the code





JUST SO YOU HAVE AN IDEA OF WHAT I HAVE IN MY .TXT FILE AND MY ARRAY.....

Data in File ----------------- Data in filesForBAT[]
crs_SP2010 ------------------ crs_SP2013.txt
usr_SP2010 ------------------ usr_SP2013.txt
crs_SP2011
usr_SP2011
crs_SP2012
usr_SP2012
crs_SP2013
usr_SP2012
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure how this is any different than the original question you asked; if you can justify the apparent duplication I won't lock this thread.
 
Eduardo Ponce de Leon
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean, i just posted 1 time and edit the post a couple of times! What original question?
 
Paul Clapham
Sheriff
Pie
Posts: 20713
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eduardo Ponce de Leon wrote:Hi,
as of now i take the first element of my array and check it agains my file, however, when i find a match in my file i dont know how to reset my Buffer reader to start reading from the top of the file again and to check the next element in my array.


I wouldn't choose a method which required reading the whole file for each entry in the array. I would do it the other way around: read the file once, and for each line in the file, see if it matches an entry in the array. If it does, then do the something.

Your example doesn't show any duplicate entries in the file or the array, so that should be the same thing.
 
Eduardo Ponce de Leon
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oooobviously 2 different posts!!!
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not really.
 
Henry Wong
author
Marshal
Pie
Posts: 20880
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Also, given the answers on how to compare two files, and the answers on how to compare to arrays, can't you just extrapolate it to how to compare a file and an array?

Henry
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic