2

Does anyone know why my csv file is not being read when including a Boolean in the reader? It works without and gives no error when compiling, however it seems like the whole read instruction is being skipped, because the System.out.println also doesn't work.

import java.io.*;
import java.util.ArrayList;
import java.net.*;


public class TransportOrderReader {

    public TransportOrder readCsvFile(String aName, int orderID, String regio, String status, Winkel winkel) {
        TransportOrder transportOrder = new TransportOrder(orderID, regio, status, winkel);
        try {
            int lineNr = 0;
            File aFile = new File(aName + ".csv");
            BufferedReader aBr = new BufferedReader(new FileReader(aFile));
            String aLine = "";
            while (aLine != null) {
                aLine = aBr.readLine();
                if (aLine != null) {
                    String [] lineParts = aLine.split(";", -1);
                    if (lineParts.length == 4) {
                        int pakketID = Integer.parseInt(lineParts[0]);
                        int volumePakket = Integer.parseInt(lineParts[1]);
                        int gewichtPakket = Integer.parseInt(lineParts[2]);
                        boolean koeling = Boolean.parseBoolean(lineParts[3]);
                        Pakket pakket = new Pakket(pakketID, volumePakket, gewichtPakket, koeling);
                        transportOrder.addMember(pakket);
                    }
                    else System.out.println("Number of attributes <> 4 on " + lineNr);
                    lineNr++;
                }
            }
            System.out.println("Aantal gelezen pakketten: " + lineNr);
        }
        catch (Exception e) { }
        return transportOrder;
    }
    
}
Benjamin Sas
  • 21
  • 1
  • 3
  • 1
    https://technojeeves.com/index.php/aliasjava1/94-ignoring-exceptions-is-dangerous Example of lines from file too please – g00se May 05 '22 at 14:31
  • @g00se examples of lines from the file would be: 123,10,25,FALSE 232,100,50,TRUE etc – Benjamin Sas May 06 '22 at 14:58
  • That wouldn't work with the code you've posted. It would be unparseable – g00se May 06 '22 at 23:14
  • @g00se Okay, why would that be unparseable? It did work without the boolean, so I assume there is something work with the format of that input? – Benjamin Sas May 07 '22 at 08:33
  • Because your code is splitting on semicolons. That file is delimited by commas so it can't be the actual file – g00se May 07 '22 at 09:12

0 Answers0