// 相对路径String relativelyPath=System.getProperty("user.dir");// 通过类的加载目录获得路径InputStream in=TestAction.class.getClassLoader().getResourceAsStream("test.txt");InputStream in=Test1.class.getResourceAsStream("/test.txt");// 通过servlet获得路径ServletContext context=this.getServletContext(); // 通过request获得路径String path=request.getSession().getServletContext().getRealPath("/");// classpath的获取路径Thread.currentThread().getContextClassLoader().getResource("").getPath()DemoController.class.getClassLoader().getResource("").getPath()// 通过属性文件读取路径InputStream in = new BufferedInputStream(new FileInputStream(name));Properties p = new Properties();p.load(in);Locale locale = Locale.getDefault(); ResourceBundle localResource = ResourceBundle.getBundle("test/propertiesTest"); String value = localResource.getString("test");