访问jar中的CSV文件 [英] Access to csv file in jar

查看:71
本文介绍了访问jar中的CSV文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行jar时,我尝试了所有方法来访问csv文件。
我将csv放在Eclipse的资源包中,当我从中运行代码时很好,但是当我从可执行文件中运行jar时,它不起作用。

I tried everything to access to csv file when a run my jar. I put the csv in resources package in Eclipse, and it's fine when I run the code from this, but it doesn't work when I run the jar from an executable.

ClassLoader c = MyClass.class.getClassLoader();
URL url = c.getResource("com/mysoft/resources/");
String path = URLDecoder.decode(url.getPath(), "utf-8");
File f = new File(path+ "VAL.csv");
if(f.exists())
...

我不不想把这个文件从罐子里拿出来。我只想读取文件,该怎么办?

I don't want to put this file out of the jar. I just want read the file, how can I do ?

推荐答案

如果您只想读取文件,则可以这样做:

If you just want to read the file, you can do this:

InputStreamReader isr = new InputStreamReader(getClass().getResourceAsStream(csvPath)));
BufferedReader br = new BufferedReader(isr);

这篇关于访问jar中的CSV文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆