how to read a txt file containing matrix form of data into 2d array of same dimensions as in the file using java -


here code:

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 {           double [][] data = new double [87][2];           file file = new file("buydata.txt");         int row = 0;         int col = 0;         bufferedreader bufrdr  = new bufferedreader(new filereader(file));         string line = null;           //read each line of text file         while((line = bufrdr.readline()) != null && row < data.length)         {            stringtokenizer st = new stringtokenizer(line,",");         while (st.hasmoretokens())         {             //get next token , store in array             data[row][col] = double.parsedouble(st.nexttoken());             col++;         }         col = 0;         row++;         }          system.out.println(" "+data[87][2]);          }      } 

it shows error:-numberformatexception :empty string

pls me

at point in file, st.nexttoken() returning empty string. because you're trying parse double, you're getting error (there no numbers in empty string double from).

the common reason bad input data. able provide subset of buydata.txt file, causes bug occur?


Comments