Read - Write to a file with JAVA

I want to create a simple program that allows me to read from a file and store the information contained in the file into an array.

The file should contain this:

ClientId        ClientAge
1                   23.6
2                   21.7
3                   15
4                   67
5                   54.1

The program should read this values and keep them in an array or list or something, then when I press for example 'a', then I list all the clients with their ages. When I press 's', then I can select an specific age.

Please give me a hand and post the whole code of the progra, so I can earn some java.

Thank you.
probineAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
This looks like classwork. Please see the guidelines about classwork
0
Mayank SAssociate Director - Product EngineeringCommented:
You can search for sample code here:

http://www.javaalmanac.com
0
probineAuthor Commented:
CEHJ

Where can I see the guidelines for class work ?
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

probineAuthor Commented:
mayankeagle I have been to that link, there are many sub links... which one is the one for reading and writing to a file. There are many, but no one suggestes anything like it

Does it, which one ?
0
sciuriwareCommented:
http://www.javaalmanac.com/egs/java.io/File2ByteArray.html

you will want to read into an array of floats or doubles, but the principle is the same.

;JOOP!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mayank SAssociate Director - Product EngineeringCommented:
0
Mayank SAssociate Director - Product EngineeringCommented:
For your case, it would be better to make a Class containing clientID and clientAge as data-members and you should make a Vector or an array of such objects and write the whole collection/ array to a file and read it from the file:

http://www.javaalmanac.com/egs/java.io/SerializeObj.html
0
Mayank SAssociate Director - Product EngineeringCommented:
You can de-serialize this way:

http://www.javaalmanac.com/egs/java.io/DeserializeObj.html?l=rel

(the link is also available in the previous page) in "Related Examples".
0
sciuriwareCommented:
You might buy the entire book.

;JOOP!
0
Mayank SAssociate Director - Product EngineeringCommented:
>> Where can I see the guidelines for class work ?

Perhaps the member-agreement. I guess you did not read it completely while joining:

http://www.experts-exchange.com/memberAgreement.jsp
0
Mayank SAssociate Director - Product EngineeringCommented:
>> You might buy the entire book.

You don't need to.

JOOP ;-)
0
probineAuthor Commented:
I do not really know java, I am trying to learn... so if you give me some code I do not know what classes to incude or anything ike it.

I would like to have something like:

Classses to include
The main program with its functions

When I have this, I can compile it and start analyzing the codes.

Can you code a simple main() for me with a class that reads from a file and prints what the file has in the screen ?
0
Mayank SAssociate Director - Product EngineeringCommented:
>> Can you code a simple main() for me with a class that reads from a file and prints what the file has in the screen

Well, now THAT is exactly against the member-agreement. We cannot provide full-code for homework. But I can give you a rough idea (just a skeletal code). Something like:

class Client
{
  public int ID ;
  public int age ;

}

(You can make the data-members private and give get/ set methods instead.)

Further, in your main () method, you can make an array to store objects: Client[] array = new Client[10] ;

Read from the array using a for loop:

for ( int i = 0 ; i < array.length ; i ++ )
  // read values for array[i].ID and array[i].age

Write it to a file using the code at the links posted above. Then you can read from the file and display the contents.
0
sciuriwareCommented:
So it's clear: you really need a good book or a basic course.
JAVA almanac is an excellent book, but it gives examples for those who know some JAVA.
I think you should run or download the JAVA tutorial from SUN first:

http://java.sun.com/docs/books/tutorial/index.html

;JOOP!
0
probineAuthor Commented:
WELL... WELL... WELL...

As I said... I need some code... I do not want to buy a book or anything like it... the code should be simple.

I already made it with out having to buy a good book or anything like it.

I would very much like to get my points refund... unless some of you thinks that deserves them !!!
0
CEHJCommented:
You won't get your points refunded probably. That only happens when you ask a legitimate question that no-one can answer. I suggest you try a simple web search for the answer if that's not too much trouble for you.
0
Mayank SAssociate Director - Product EngineeringCommented:
You already have enough code samples on this page, and links to more samples too. You cannot state that you need a refund after we have given so many answers (because they would be helpful to you) - its not that they are irrelevant.
0
sciuriwareCommented:
The problem is that 'probine' doesn't want to learn (enough basical) JAVA (yet).

It's like asking info about the steering wheel, but avoiding to learn to ride the car.

EE is an excellent place to get yourself put on the right track, but we can't write all
programs for you entirely. If you look around, you'll see that we all seek knowledge,
not take-away-food.

;JOOP!
0
Mayank SAssociate Director - Product EngineeringCommented:
Please proceed with that recommendation.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.