Question
My project is an 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
Then the tool class is written like this, 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("属性key")); }
If I write the properties as follows
The project is directly Can't start, reported error
Solution
After research, using "\" in properties is equivalent to the escape character of java
If you want to write out the effect of \, just modify it You can write it as follows
#Then the project is started, and then the path inserted into the database is normal~
The above is the detailed content of How to write backslash \ in Java's .properties file?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Notepad++7.3.1
Easy-to-use and free code editor

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

WebStorm Mac version
Useful JavaScript development tools

SublimeText3 Linux new version
SublimeText3 Linux latest version