- Package com.util;
- Import Java.io.BufferedInputStream;
- Import Java.io.FileInputStream;
- Import Java.io.InputStream;
- Import java.util.Properties;
- /**
- * Read Config file tool class
- * @version 1.0
- * @since JDK 1.6
- */
- Public class Propertiesconfig {
- /**
- * Get properties from the entire configuration file
- * @param filePath file path, that is, the path to the package where the file is located, for example: java/util/config.properties
- */
- public static Properties ReadData (String filePath) {
- FilePath = Getrealpath (FilePath);
- Properties props = new properties ();
- try {
- InputStream in = new Bufferedinputstream (new FileInputStream (FilePath));
- Props.load (in);
- In.close ();
- return props;
- } catch (Exception e) {
- E.printstacktrace ();
- return null;
- }
- }
- private static string Getrealpath (String filePath) {
- //Get the absolute path and truncate the "file:/" prefix of the path
- return propertiesconfig. Class.getResource ("/" + FilePath). toString (). substring (6);
- }
- }
Read Config file tool class Propertiesconfig.java