Importing a .csv file data into java table showing incomplete information

653 Views Asked by At

I'm trying to import a .csv file to display in my Java Table. But it shows incomplete data after reaching a certain point. enter image description here

When I change the data to previous ones it displays just fine enter image description here

My csv file looks fine too.. enter image description here

Finally this is how I read the file into the table from a menu item in my interface

        File file = new File("C:\\Users\\User\\Desktop\\Emerging Coursework\\12_book_list_csv.csv");
        try{
            Scanner inputStream = new Scanner(file);
            inputStream.nextLine();
            while (inputStream.hasNextLine()) {                    
                String data = inputStream.nextLine();
                String[] values = data.split(",");
                
                for(int i = 0; i < values.length; i++){
                    System.out.println(values[i]);
                }
                int rowCount = browseTable.getRowCount();
                System.out.println("rowCount: " + rowCount);
                int columnCount = browseTable.getColumnCount();
                System.out.println("columnCount: " + columnCount);
                int nextRow = 0;
                boolean emptyRowFlag = false;
                String testValue;
                do {
                    testValue = (String) browseTable.getValueAt(nextRow, 0);
                        if (testValue != null && testValue.length()!=0) {
                            System.out.println("testvalue:" + testValue);
                            System.out.println("testValue.length" + testValue.length());
                            nextRow++;
                        } else{
                        emptyRowFlag = true;
                        }            
                    } while(nextRow < rowCount && !emptyRowFlag);

                    for (int i = 0; i < columnCount; i++){
                        browseTable.setValueAt(values[i], nextRow, i);
                    } 
            }
        } catch(Exception e){
            
        }
0

There are 0 best solutions below