Java scanner delimiter error csv java end of line Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Java scanner delimiter error csv java end of line without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I’m receiving an InputMismatchException while scanning in the last int of a csv.

public class TradeSim {
    public void readFile(String fileName) {
        try {
            // file name and absolute path
            File file = new File(fileName);
            String fullPath = file.getAbsolutePath();
            System.out.println("Using file:n" + fullPath + "n");

            // set File Input Stream to Full Path
            FileInputStream inputStream = new FileInputStream(fullPath);

            // open input stream and retrieve data
            Scanner scanner = new Scanner(inputStream);
            while (scanner.hasNext()) {
                String data =; // gets a whole line
        } catch (Exception e) {
            System.out.println("Encountered Error reading file:n" + e.toString() + "n");

    public void parseCSVLine(String line) {
        Scanner scanner = new Scanner(line);
        long timeStamp = scanner.nextLong();
        System.out.println("timeStamp: " + timeStamp);
        String symbol =;
        System.out.println("symbol: " + symbol);
        int quantity = scanner.nextInt();
        System.out.println("quantity: " + quantity);
        int price = scanner.nextInt(); //Error occurs here!!
        System.out.println("price: " + price);
        Trades trades = new Trades(timeStamp, symbol, quantity, price);

File content:



Using file:
/Users/andrewkeithly/netbeansprojects/Trades Exercise/input.csv

timeStamp: 51300051409
symbol: fbc
quantity: 273
Encountered Error reading file:


Problem Solved: System.getProperty("line.separator") was looking for a Unix specific delimiter in which the csv did not use. Simply changing the code to scanner.useDelimiter("r?n"); solved my problem. Thanks @Tom !

We are here to answer your question about Java scanner delimiter error csv java end of line - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji