load();

I am completely lost i have to load a text file, and dont have a clue, could someone help me please;

here is my save mehtod;

publicvoid save(){

PrintWriter out =null;

try{

out =new PrintWriter(new FileWriter(storageFile));

out.println(communityName);

for(int i = 0; i <= lastIndex; ++i){

alienArray[i].writeToFile(out);

out.println();

}

}catch (Exception e){

}finally{

try{

out.close();

}catch (Exception e){

}

}

}

[1299 byte] By [static_firea] at [2007-10-2 21:45:50]
# 1
Define "load." Do you want a separate String array element for each line, or something else?
Dick_Adamsa at 2007-7-14 1:01:24 > top of Java-index,Java Essentials,Java Programming...
# 2

i want to load data fromo a text file into an array what i have tried so far is this. and it does not work

public void load(){

BufferedReader in = null;

AlienCreature creature = null;

try{

File file = new File(storageFile);

if(! file.exists()){

System.out.println("Not valid");

return;

}

in = new BufferedReader(new FileReader(file));

communityName = in.readLine();

while(in.ready()){

addAlien(creature);

}

} catch (Exception e){

} finally {

try{

in.close();

}catch(Exception e){}

}

}

static_firea at 2007-7-14 1:01:24 > top of Java-index,Java Essentials,Java Programming...
# 3
Hi, what do you mean? If you need to read text file then you can use example from "How to get specified string from file?" topic.Regards,Sasha.
SashaPa at 2007-7-14 1:01:24 > top of Java-index,Java Essentials,Java Programming...
# 4
Don't start new threads for this all over the place. Read my reply #4 in[url= http://forum.java.sun.com/thread.jspa?threadID=741967&messageID=4253477#4253477]another thread[/url] of yours.kind regards,Jos
JosAHa at 2007-7-14 1:01:24 > top of Java-index,Java Essentials,Java Programming...
# 5
okay well i add a bunch of stuff to an array and it saves to a text file, i want to write a method that will take that information from the text file and load it back into the array (when the program is reopened)
static_firea at 2007-7-14 1:01:24 > top of Java-index,Java Essentials,Java Programming...
# 6

i tried this cose out and it only displays the data once the program is about to exit

public void load(){

BufferedReader in = null;

AlienCreature creature = null;

String fileName = "AlienCreature.txt";

String line = "";

try

{

in = new BufferedReader(new FileReader(fileName));

while(in.ready())

{

line = in.readLine();

System.out.println(line);

}

in.close();

}

catch(IOException e){

System.out.println("Error reading " + fileName);

}

}

i need to load the information into the array

static_firea at 2007-7-14 1:01:24 > top of Java-index,Java Essentials,Java Programming...
# 7

What do you mean doesn't work...how is your file formatted?

This is not going to work at all, but to tell you what you need to do you need to give us all relavant info.

communityName = in.readLine();

while(in.ready()){

addAlien(creature);

}

Norweeda at 2007-7-14 1:01:24 > top of Java-index,Java Essentials,Java Programming...
# 8
If I have my logins straight, trying to get a clear explanation of the question from this one is a fruitless excercise.(I might have him mistaken with someone else though.)
jverda at 2007-7-14 1:01:24 > top of Java-index,Java Essentials,Java Programming...