here i have code it work well here i have assigned size of the row and column. how can i get the row and column value from text file.

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.StringTokenizer;
public class csvimport5 {


    public static void main(String[] args) throws IOException {

		
        File file = new File("D:\\PROJECT_JAVA\\buydata.txt");
        int row = 0;
        int col = 0;
		//Scanner in = new Scanner(System.in);
		double [][] data = new double [87][2];
        BufferedReader bufRdr  = new BufferedReader(new FileReader(file));
        String line = null;
		
        while((line = bufRdr.readLine()) != null && row < data.length)
        {   
			StringTokenizer st = new StringTokenizer(line,",");
			while (st.hasMoreTokens())
			{
				try {
					  data[row][col] = Double.parseDouble(st.nextToken());
					} catch (NumberFormatException e) {
					}
				col++;
			}
			col = 0;
			row++;
        }
        System.out.println(" "+data[86][1]);     

      }

    }

What does the text file contain? If it has a record with two Strings that are the row and column values, you could use the Scanner class to read and convert those two Strings into int values.
If you read the whole line as a String then you will need to extract the two Strings that are the numbers and convert them to int using the Integer class's parsing method.
I assume that the row and column numbers are int values. You are treating them as double which seems strange as I think of row numbers as whole numbers.

my text file contain 2D matrix double value.here i have assign row and column size(row=87,col=3).i have to find the row and column size before assigning value into matrix.

have to find the row and column size before assigning value into matrix.

Where are the row and column size values? Are they in the file?
If you read the data in the file into an arraylist you would not have to worry about the size of the data, the arraylist will resize itself as needed.

for example

8.00,28.00  
18.00,28.00 
8.00,23.00  
12.00,20.00 
15.00,30.00 
12.00,32.00

here my file contain 2 column and 5 rows.how can i find the row and column size when i change the file.array list is possible but i want 2D matrix to do the calculation

If you read the file into an array list, you will know how many rows there are.
You can then create an array with the correct size and copy the data from the arraylist to the 2D array.

yes.but it will take unnecessary time. do you have any suggestion.

This article has been dead for over six months. Start a new discussion instead.