I am trying to read a CSV file having no. of rows=row and no. of columns=col by the following method:

public static String[][] FileIntoArray(int row, int col, String FileName){
        int Filerow=0;
        int Filecol=0;
        String line;
        String[][] FileArray= new String[row][col];

        File file = new File(FileName);


            try{
                BufferedReader bf  = new BufferedReader(new FileReader(file));
                try {
                    while((line = bf.readLine()) != null){

                    StringTokenizer st = new StringTokenizer(line,",");
                    while (st.hasMoreTokens()){
                            FileArray[Filerow][Filecol]= st.nextToken();
                            Filecol++;                          
                            }


                    Filecol = 0;
                    Filerow++;
                    }

                }catch (IOException e){
                    }
            }catch(FileNotFoundException f){
                }
    return FileArray;

    } 

Now suppose, the code reads the file
1,2,3,4
,,4,5

As you could see, there are some entries absent on 2nd row. So what will it read then if the entries are not present?

You should just get a zero-length String "" for the missing entries.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.