|
Page 1 of 1 |
[sYn]
[Moderator] Elitist
Posts: 8374
|
Posted: Sun, 8th Jan 2006 00:16 Post subject: Java Gods? |
|
 |
I'm in a bit of a pickle, and if I remember correctly we have some Java god's on the forum, so lets hope you can help me out. I have to write a polymorphic java program to display images, move them, change them and pull settings from a file. Now I have a lot of the ground work done, but I always have issues with pulling information from files..
Lets say I have a file with the following information in it:
Shape: Circle, Position: ***, ***, Size: ***, ***, Colour: ***, Fill: ***
The stars obviously representing values like numbers, or colours.. How would I pull that into my program form a file? currently I have the following code which pulls in data one line at a time..
Code: | public boolean load(String file1)
{
boolean b = false; // Dummy - Unused
try
{
FileReader file = new FileReader("default.lst"); // Opens file "default.lst" or ignores if unavalible
BufferedReader in = new BufferedReader(file);
int i = 1;
String line = null;
while((line = in.readLine()) != null) // Sets up and "end of file" while loop scanning each line
{ // and putting it into a varliable until there are no more lines
switch(i)
{
case 1 : contact[position][0] = line;break; // each line is inputted into the array
case 2 : contact[position][1] = line;break;
case 3 :
contact[position][2] = line;
position++; // position is incremented so the whole file is loaded line by line
i=0;
break;
}
i++; // counter is incremented
}
in.close(); // Buffer is closed
}
catch (Exception e) { // Exception is caught
System.out.println(e);
}
totalposition = position;
return b; // Dummy - Unused
} |
Thoughts? Any idea's would be great ! - Oh, and I only have a few days.. so quick help would be awsome ..
|
|
Back to top |
|
 |
|
|
Back to top |
|
 |
|
Posted: Sun, 8th Jan 2006 14:14 Post subject: |
|
 |
Avenger is right. That sounds like a good way.
For the splitting thing have a look at the StringTokenizer class (java.io or java.util methinks).
This class does all this splitting work.
|
|
Back to top |
|
 |
|
|
Back to top |
|
 |
Page 1 of 1 |
All times are GMT + 1 Hour |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB 2.0.8 © 2001, 2002 phpBB Group
|
|
 |
|