This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to iterate through an Array of objects and a file at the same time?

 
Adam Cripps
Ranch Hand
Posts: 41
Eclipse IDE Linux Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a scenario where I have an Array of CurriculumSubject objects (which in turn has creted 15 JTextField object instances) and then a text file.

I want to iterate through the CurriculumSubject Array (and each JTextField for each subject) and go through the text file line by line, setting each JTextField to one line - and then move on to the next.

Currently, I have this method which receives a File object:



How can I integrate a BufferedReader in to this so that as I move through the 15 JTextFields, the BufferedReader reads the next line of the file?

TIA
Adam
 
Campbell Ritchie
Sheriff
Pie
Posts: 47292
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you need a reader for text fields? Can’t you use their getText() method?
 
Randall Twede
Ranch Hand
Posts: 4353
2
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell misunderstood. i see what you want to do. set the texFields from info in the file. if someone doesn't answer first i'll see if i can find something like that.
i havent read this but it seems like what you want
read file
 
Adam Cripps
Ranch Hand
Posts: 41
Eclipse IDE Linux Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Randall - you are correct. The BufferedReader is to handle the text file and go through the file line by line. I already have managed to access the JTextFields through set and get, so that part of the problem is sorted - it's reading the file line by line that I really need help with. Thanks.
 
Winston Gutkowski
Bartender
Pie
Posts: 9484
50
Eclipse IDE Hibernate Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adam Cripps wrote:it's reading the file line by line that I really need help with.

Well BufferedReader.readLine() returns the next line if there is one; or null if there isn't. Maybe that'll help.

Winston
 
Adam Cripps
Ranch Hand
Posts: 41
Eclipse IDE Linux Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Winston. However, I will need to iterate through the file - how do I knit the two iterations together?
 
Winston Gutkowski
Bartender
Pie
Posts: 9484
50
Eclipse IDE Hibernate Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adam Cripps wrote:Thanks Winston. However, I will need to iterate through the file - how do I knit the two iterations together?

I suggest you have a think about it and try something yourself. I've already given you all the information you need to write a read loop of your own using either for or while.

Winston
 
Randall Twede
Ranch Hand
Posts: 4353
2
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so true. often i post questions here and then after i think about it, i come up with the answer.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic