Read Config file tool class Propertiesconfig.java

Source: Internet
Author: User

  1. Package com.util;
  2. Import Java.io.BufferedInputStream;
  3. Import Java.io.FileInputStream;
  4. Import Java.io.InputStream;
  5. Import java.util.Properties;
  6. /**
  7. * Read Config file tool class
  8. * @version 1.0
  9. * @since JDK 1.6
  10. */
  11. Public class Propertiesconfig {
  12. /**  
  13. * Get properties from the entire configuration file
  14. * @param filePath file path, that is, the path to the package where the file is located, for example: java/util/config.properties
  15. */
  16. public static Properties ReadData (String filePath) {
  17. FilePath = Getrealpath (FilePath);
  18. Properties props = new properties ();
  19. try {
  20. InputStream in = new Bufferedinputstream (new FileInputStream (FilePath));
  21. Props.load (in);
  22. In.close ();
  23. return props;
  24. } catch (Exception e) {
  25. E.printstacktrace ();
  26. return null;
  27. }
  28. }
  29. private static string Getrealpath (String filePath) {
  30. //Get the absolute path and truncate the "file:/" prefix of the path
  31. return propertiesconfig.  Class.getResource ("/" + FilePath). toString (). substring (6);
  32. }
  33. }

Read Config file tool class Propertiesconfig.java

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.