问题描述
我正在尝试编写一个静态函数,该函数读取 CSV 并从该 CSV 输出值。 我在阅读它时遇到问题,因为每次我收到 fileNotFound 异常,但我相信我的路径是正确的。
这是代码
public class DateFormatUtils {
private static String dateFormatCsvPath = "csv/country_date_format.csv";
public static String getDateFormatByLocale(Locale Locale) {
List<Map<String,String>> mapList = Collections.emptyList();
String fileExtension = "csv";
try {
InputStream inputStream = new FileInputStream(dateFormatCsvPath);
mapList = ExcelUtils.read(inputStream,fileExtension);
String a = "a";
} catch (FileNotFoundException e) {
e.printstacktrace();
} catch (IOException e) {
e.printstacktrace();
}
return "a";
}
}
这是我的项目截图,你可以看到,相对于我的类,文件在csv/country_date_format.csv
下。我也试过 ./csv/country_date_format.csv
和 /country_date_format.csv
无济于事。
我也尝试将我的文件作为资源获取,但也没有成功String path = DateFormatUtils.class.getClass().getResource("csv/country_date_format.csv").getPath()
我不明白为什么我仍然收到找不到文件的异常。谁能给我指点一下?
csv 和其余代码捆绑在 JAR 中
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)