I don't get yr problem :
/*
* Reads a text file and return the contents of the file
* as an array of strings. Each element in the array contains
* one line from the text file.
*
* "str" is each line in the file
*/
private static readFileToArray (String filename)
throws Exception
{
filename = ("a:\\JavadocPart1.txt");
BufferedReader inFile = new BufferedReader (new FileReader (filename);
String str = null; // set initial
int i = 0; // declare counter variable
// Read text one line at a time and assign each to a string element
while ((str = inFile.readLine ()) != null)
{
i++; // <-- what do U do with this ?
String [] anArray = new String [1000]; // <-- This is really pointless !
anArray = str;
} // end while
return (anArray );
} // end readFileToArray
I would advise you to do this like here under.
See the code below it should be more efficient, doesn't declare unneeded variables & id safe event for files greater than "1000" lines ... /*
* Reads a text file and return the contents of the file
* as an array of strings. Each element in the array contains
* one line from the text file.
*
* "str" is each line in the file
*/
private static readFileToArray (String filename)
throws Exception
{
filename = ("a:\\JavadocPart1.txt");
BufferedReader inFile = new BufferedReader (new FileReader (filename);
String str = null; // set initial
int i = 0; // declare counter variable
// Read text one line at a time and assign each to a string element
ArrayList array = new ArrayList ();
while ((str = inFile.readLine ()) != null)
array.addElement ( str );
// end while
return (array.toArray ( new String[array.size()]) );
} // end readFileToArray
Thomas SMETS,
SCJP2 - Brussels