1,获得项目中的文件(test.txt)的路径
String filePath=this.getCalss().getClassLoader().getResource("test.txt").getPath();
2,将文件放进tomcat文件内,在java中获取文件
String filePath=request.getServletContext().getRealPath("/");
filePath=filePath.substring(0,filePath.lastIndexOf("\\"));
filePath=filePath.substring(0,filePath.lastIndexOf("\\"));
filePath=filePath.substring(0,filePath.lastIndexOf("\\"));
filePath=filePath+"\\test.txt";
最后得到的filePath路径为:D:\java\tomcat7\test.txt