Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

read a file ?

 
sam robert
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am trying to develop a small application. I have a set of questions in a file and i need to read these from the file, as question by question an dneed to display them on the screen at the same time. I? am quite new to this. Can someone please help.
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Step to develop your program.

1. read all data in file.
2. Parse all data in to some Bean class to display and keep bean in List/Vector.
3. Display all data in List/Vector to screen/UI.
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Example Read data in File

 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sam,
You can also search old posts, which are related to file accessing, using the keyword "file" in this forum...

I do believe some old posts are pretty useful for us to get to know about the things that we are willing to know...

Hope it helps...
 
sam robert
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks guys ...but i am still not clear as to how do i store the read part in a vector ....please explain that ....i appreciate it....
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since you want to display the read question on the screen at the same time , why do you need a vector. You could print the read question immediately without requiring any temporaty storage.
 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by sam robert:
thanks guys ...but i am still not clear as to how do i store the read part in a vector ....please explain that ....i appreciate it....


sam, if you want to keep all the lines in a vector, you can modify somkit's code as the following... As Pradeep mentioned, if you are directly printing the contents of the file to the console screen, you don't need a vector to store them... But if you want to use them in the future, you might need it...



Hope it helps...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic