从目录中读取文件时出现问题
Having issue reading a file from directory
我有 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] + "]");
}
您需要提供csv文件的完整路径。
喜欢
String csvFile = "C:/temp/abc.csv";
我有 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] + "]");
}
您需要提供csv文件的完整路径。 喜欢
String csvFile = "C:/temp/abc.csv";