A: If the container is WebSphere, then the red place below cannot be added "/", and if it is Tomcat, add "/",
Java code
- String Path = this . Class.getResource (""). GetPath () +"config.properties";
- Properties properties= new properties ();
- Properties.load (new FileInputStream (path));
If your config.properties is under a package, bring the package together, such as: Config.properties under the Com.df.util package:
Java code
- String Path = this . Class.getResource (""). GetPath () +"com/df/util/config.properties";
- Properties properties= new properties ();
- Properties.load (new FileInputStream (path));
Second: If you use spring in your project, you can also get it,
Java code
- Import Org.springframework.core.io.Resource;
- Import Org.springframework.core.io.ClassPathResource;
- Resource Resource = new Classpathresource ("config.properties"); Read directly under SRC, under the class file
- Properties properties= new properties ();
- InputStream in = Resource.getinputstream ();
- Properties.load (in);
WebSphere Gets the project under the. Properties path