【发布时间】:2012-09-27 11:38:34
【问题描述】:
我得到一个这样的文件:
String myFile = "D:/dev/workspace/MyProject/WebContent/stats/stats.csv";
File statsFile = new File(myFile);
但我只想将相对路径设为stats/stats.csv。我不想在我的代码中写完整的路径。
在 servlet 中,我是这样做的:
File statsFile = new File(this.getServletContext().getRealPath("/") + "stats/stats.csv");
但这里它不在 servlet 中。那么java类中的等价方式是什么?
【问题讨论】: