有问题从目录中读取文件

时间:2015-06-16 05:27:27

标签: java-ee tomcat7 bufferedreader filereader

我有csv文件,当我尝试从以下代码中读取时,它会抛出错误FileNotFound。有人可以为此建议解决方案。

    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 个答案:

答案 0 :(得分:1)

您需要提供csv文件的完整路径。 喜欢

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