In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
Today, I will talk to you about how to import properties files from static blocks or static methods. Many people may not know much about it. In order to let you know more, Xiaobian summarizes the following contents for you. I hope you can gain something according to this article.
How to load properties files in static blocks or static methods.
Here we use ClassLoader.class.getResourceAsStream () to load the properties file in the classpath within the static block. Make sure the class is available in the classpath code: ? 12345678910112131415161718192021222324252627282930313233435 package com. java2novice.properties;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class MyPropInstanticBlock{private static Properties;
static{InputStream is=null;try{prop=new Properties();is=ClassLoader.class.getResourceAsStream("/sample.Properties");prop.load(is);}catch(FileNotFoundException e){e.printStackTrace();}catch(IOException e){e.printStackTrace();}
public static string getPropertyValue (string key){return prop.getProperty (key);}
Common static void main (string a[]){System.out.println ("db.host:+getPropertyValue ("db.host");System.out.println ("db.user:+getPropertyValue ("db.user");System.out.println ("db.password:+getPropertyValue ("db.password");} sample.properties? 1234db.host=appdomain.java2novice.com db.user=java2novice db.password=mypassword db.service=orcl
Input: db.host: appdomain.java2novice.com db.user: java2novelty db.password:mypassword
Having read all this, do you have any idea how to import properties files from static blocks or static methods? If you still want to know more knowledge or related content, please pay attention to the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.