Having issue reading a file from directory

44 views Asked by At

I have csv file and when i try to read from the following code it throws an error FileNotFound. Can someone please suggest the solution for this.

    String csvFile = "spring/batch/report.csv";
    BufferedReader bufferReader = null;
    String line = "";
    String cvsSplitBy = ",";
    try {

        System.out.println("Job A has been started................");
        bufferReader = new BufferedReader(new FileReader(csvFile));
        while ((line = bufferReader.readLine()) != null) {

            // use comma as separator
            String[] country = line.split(cvsSplitBy);

            System.out.println("Country [code= " + country[4] + " , name="
                    + country[5] + "]");
        }
1

There are 1 answers

2
Jaya Dwivedi On BEST ANSWER

You need to provide the full path of csv file. Like

String csvFile = "C:/temp/abc.csv";