dcsimg
pls help urgent....retrieving values
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Sharen_Su
Posted On:   Sunday, July 7, 2002 08:24 AM

Actually what i want is very simple. I have a .txt file (eg. testing.txt) i already stored the values into vector of vectors. The vector format will become like (eg.): [[array,row,array,col,rmean,gmean],[1,1,1,1,345,654],[1,1,1,2,678,643]] Let say if i want to retrieve the column "rmean", how should i be able to do that? somebody told me to use String rMean = String (((Vector(outervector.elementAt(i))).elementAt(j); providing i know the order of placing.In fact, i don't know about the placing of elements, i will just retrieve all the values from the .txt file and stored it in vector of vectors.I do not need to convert anything to excel and also do not need to make use of database. I just need to retrieve a certain column out.can somebody help me by showin   More>>

Actually what i want is very simple. I have a .txt file (eg. testing.txt) i already stored the values into vector of vectors. The vector format will become like (eg.): [[array,row,array,col,rmean,gmean],[1,1,1,1,345,654],[1,1,1,2,678,643]] Let say if i want to retrieve the column "rmean", how should i be able to do that? somebody told me to use String rMean = String (((Vector(outervector.elementAt(i))).elementAt(j); providing i know the order of placing.In fact, i don't know about the placing of elements, i will just retrieve all the values from the .txt file and stored it in vector of vectors.I do not need to convert anything to excel and also do not need to make use of database. I just need to retrieve a certain column out.can somebody help me by showing me some codes? codes for data to be stored in vector of vectors:

			
FileInputStream fis=new FileInputStream(f);
BufferedInputStream bis = new BufferedInputStream(fis);
DataInputStream dis=new DataInputStream(bis);
String row;
String col;
Vector rows = new Vector();
Vector cols = null;

//loop through rows
while((row = dis.readLine())!= null)
{
StringTokenizer st = new StringTokenizer(row, " ");

//create a new vector for each row's column

cols = new Vector();

//loop through columns
while (st.hasMoreTokens())

{
cols.add(st.nextToken());
}

//add the column Vector to the rows vector
rows.add(cols);


}

//close file

dis.close();

   <<Less

Re: pls help urgent....retrieving values

Posted By:   John_Huang  
Posted On:   Friday, July 12, 2002 02:23 PM



Is this what you want?


//assuming you know "rmean" is in the first row.

//if you don't, tell me

Vector first_row = (Vector)rows.firstElement();

//find the index of the column, assuming you the first
occurance of "rmean" is what you want

int col_pos = first_row.indexOf("rmean");

//result is used to store retrived column data

Vector result = new Vector();



//iterate through each row of rows, and get the the
element of specific column

Iterator row_iterator = rows.iterator();

Vector current_row;



while (row_iterator.hasNext())

{

current_row = (Vector)row_iterator.next();

result.add(current_row.elementAt(col_pos));

}



//now result contains all the data of the column of "rmean"


John
About | Sitemap | Contact