在javaweb下有时我们需要读取src中的文件,可以通过以下代码实现
File file=new File(this.getClass().getResource("/").getPath());
String path=file.getAbsolutePath();
System.out.pring(path);
输出结果: D:\apache-tomcat-6.0.35\webapps\WelfareWork\WEB-INF\classes
在javaweb下有时我们需要读取src中的文件,可以通过以下代码实现
File file=new File(this.getClass().getResource("/").getPath());
String path=file.getAbsolutePath();
System.out.pring(path);
输出结果: D:\apache-tomcat-6.0.35\webapps\WelfareWork\WEB-INF\classes