In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces the relevant knowledge of how to write "\" in the Java properties file. Many people will encounter this dilemma in the operation of actual cases. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
problem
Mine is a ssh project. I need to upload a file, and then the file path needs to read the properties configuration.
There is config/application.properties under resource.
And then the tool class is written like this, and this can be used.
Import java.io.IOException;import java.io.InputStream;import java.util.Enumeration;import java.util.MissingResourceException;import java.util.Properties;import java.util.ResourceBundle;public class PropertiesUtil {private static Properties props = new Properties (); private static PropertiesUtil instances = null; private static String NAME = "config//application"; public static PropertiesUtil getInstance () {if (null = = instances) {instances = new PropertiesUtil ();} return instances;} private PropertiesUtil () {init (NAME) Public synchronized void init (String sPropFilePathName) throws MissingResourceException {String propFile = sPropFilePathName; ResourceBundle bundle = ResourceBundle.getBundle (propFile); Enumeration enume = bundle.getKeys (); Object key = null; Object value = null; while (enume.hasMoreElements ()) {key = enume.nextElement (); value = bundle.getString (key.toString ()); props.put (key, value); public String getProperty (String key) {return props.getProperty (key) Public static String getValue (String filePath, String key) {InputStream in = null; String value = null; try {in = PropertiesUtil.class.getResourceAsStream (filePath); props.load (in); value = props.getProperty (key) } catch (Exception e) e.printStackTrace ();} finally {try {if (in! = null) {in.close () }} catch (IOException e) e.printStackTrace (); return value;} public static void main (String [] args) {System.out.println (PropertiesUtil.getInstance (). GetProperty ("attribute key"));}
If I write as follows on properties
The project could not be started directly and was reported to error.
Solve
After research, properties uses "\" as the escape character of java.
If you want to write the effect of\, you only need to modify the following words
Then the project gets up, and then the path inserted into the database is also normal.
This is the end of the introduction of how to write "\" in the Java properties file. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.