shragi
asked on
read file to list and store in array
I had a file I need to read it and store it in array...
I am done with it...
but i found a problem and now i want to read the file into a list and then store it into array...
below is the code that i had written with out reading it into list...
a friend of this forum gave me the below link...
http://helpdesk.objects.com.au/java/how-do-i-read-a-text-file-line-by-line-into-a-list
so can any one tell me how to apply the above concept in above link to my code...
I am done with it...
but i found a problem and now i want to read the file into a list and then store it into array...
below is the code that i had written with out reading it into list...
a friend of this forum gave me the below link...
http://helpdesk.objects.com.au/java/how-do-i-read-a-text-file-line-by-line-into-a-list
so can any one tell me how to apply the above concept in above link to my code...
class ReadFile
{
int kMaxLines = 60000;
double[][] valuePairs = new double[2][kMaxLines];
public void fileRead()
{
try
{
int kMaxLines = 60000;
FileInputStream fstream = new FileInputStream("/output.txt");
DataInputStream datastream = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(datastream));
String strLine;
int line = 0;
while ((strLine = br.readLine()) != null)
{
String temp_strs[] = strLine.split("\t");
for (int j = 0; j < 2; j++)
valuePairs[j][line] = Double.parseDouble(temp_strs[j]);
line++;
}
datastream.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
what r u trying to do with that code?
while ((strLine = br.readLine()) != null)
{
String temp_strs[] = strLine.split("\t");
for (int j = 0; j < 2; j++)
valuePairs[j][line] = Double.parseDouble(temp_st rs[j]);
the above line just overrites the exisiting!
while ((strLine = br.readLine()) != null)
{
String temp_strs[] = strLine.split("\t");
for (int j = 0; j < 2; j++)
valuePairs[j][line] = Double.parseDouble(temp_st
the above line just overrites the exisiting!
Yes it can be done in that way, but it is easier to understand using the way I have done.
ASKER
instead of above format can it be done as shown in my format...
i.e.,
double[][] valuePairs = new double[2][kMaxLines];