【发布时间】:2018-03-12 14:53:38
【问题描述】:
服务器:tomcat。
我创建了一个 Servlet 来调用 JAVA 程序来处理 CSV 文件。
代码 new ToJSON().main(files) 会将 csv 文件处理为 json。
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String [] files = request.getParameter("files").split(",");
System.out.println(String.join(",", files));
new ToJSON().main(files);
////call the java program to convert CSV files to json then sent the file name or the contain back.
response.getWriter().append("data.json");
}
SEVERE: Servlet.service() for servlet [charting.servlet.ChartingServlet] in context with path [/Charting] threw exception
java.io.FileNotFoundException: BankFileLine.csv (No such file or directory)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at java.io.FileInputStream.<init>(FileInputStream.java:93)
at java.io.FileReader.<init>(FileReader.java:58)
at format.LoadCSVFile.iterable(LoadCSVFile.java:60)
at format.LoadCSVFile.getMaxLength(LoadCSVFile.java:44)
at format.LoadCSVFile.<init>(LoadCSVFile.java:26)
at toJSON.ToJSON.main(ToJSON.java:26)
但我不断收到 filenotfoundexception。我试图将文件放入 WebContent 和 src。他们都没有工作。我尝试添加路径:localhost:8080/ChartingServlet/filename,还是不行。
这里是目录 Here is the directories of the project files
我的问题是我应该把文件放在哪里?
【问题讨论】:
-
给出文件的绝对路径。你不能依赖当前的工作目录。
标签: java eclipse jakarta-ee