If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

from file to class

Hi ,
I'm just a beginner in java programming and I would like to ask how to manage the reading from file to class.
I mean, I have a file containing this kind of information:

Abbiati%goalkeeper%MILAN%2
....
....

the 1st string before the % is a name of the player (in a soccer team) the 2nd is his role, the 3rd is his team and the last is the credits of his quotation.
Well, what I want to do is to read these infos from file and save them in a class by using some arrays.
For example I will create:

Hi!
Many thanks for your support!!
You're right, I didn't specify if I have to do an application or an Applet ....
I have to do an application!
Well, I've read your code and I think to have caught the meaning of everything a part of the last few lines:

I have also to say that I know only C language so I can't use the Vector class you suggested me. With C language I would have used a struct, but I think that Java doesn't support this kind of data... I'm a VERY beginner you know
Other thing: can I use a similar code to do the opposite task? that means to write infos from array to file?
many thanks again! bye!!

Sorry that piece of code was a copy and paste problem. There is no thread defined in this code but for your information that code when executed will stop the thread for specified milliseconds (15 in the given case) thus if you are designing an animation of images and you want each image to be displayed for specified time then you will need this kind of code with sleep() method. But in the example I posted it was not required and it is a mistake on my part - this is good observation

Yes you can write the array back to the file with the only difference that istead of FileReader class you will have to create instance of FileWriter class

Now in your main code or application you will have to create an instance for each line of data in your file thus an example can be:

player player1= new player("Abbiati","goalkeeper","Milan","2");

You will have to create as many "player" objects as the number of players in your data file - you can also create an array of players like
teamplayer[] =new player[team_size];

This is a static method of creating an array and you will have to ensure that the size does not exceed the array limit. Alternately you can also create a dynamic array but "vectors" have the advantage of expanding/shrinking as required and you do not have to worry about the size of the array required or for cleaning up allocated memory when the object is no longer in use. All these things are automaticlly taken care of in vectors.

The idea to create a class (like the player class you have suggested) that simulates the struct data of C language is very great. I think I can manage it quite good!

Well, I used the code you gave me few times ago to read datas from file and I also added a piece of code to share my line in tokens. I used the symbol of percentage (%) as delimit's mark since the blank spaces were not usefull to my purpose.
Here below you see the code:

Notice that it works!!!
Ok, after this I run into another problem...
Instead of print these tokens with a System.out.println I should visualize them into a table consists in 30 rows (number of player per team) and 5 columns (name and surname, role, team, credists.. ).
I try to use a JTable to accomplish this task, but I must say that it's appeared to me a little bit complicate....
Can you suggest me some about it?
Thanks again for your availability!!!

PS: don't worry for your copy/paste error, as a matter of fact I learned more about java!!