最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

解決Java?properties文件里面如何寫"\"的問題

 更新時(shí)間:2022年04月14日 15:54:41   作者:copa~  
由于properties使用“\”相當(dāng)于是java的轉(zhuǎn)義符,如果想要寫出\的效果,只需修改相應(yīng)的寫法即可,對java?properties文件里的"\"寫法感興趣的朋友一起看看吧

問題

我的是ssh項(xiàng)目,需要做一個(gè)文件上傳,然后文件路徑需要讀取properties配置
在resource下有config/application.properties

在這里插入圖片描述

然后工具類是這樣寫的,這個(gè)是可以用的

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"));
}

如果我在properties寫成如下

在這里插入圖片描述

項(xiàng)目直接啟動(dòng)不起來,報(bào)了error

解決

經(jīng)過研究,properties使用“\”相當(dāng)于是java的轉(zhuǎn)義符
如果想要寫出\的效果,只需修改如下寫法即可

在這里插入圖片描述

然后項(xiàng)目起來了,然后看數(shù)據(jù)庫插入的path也正常~

在這里插入圖片描述

到此這篇關(guān)于Java properties文件里面如何寫“\“的文章就介紹到這了,更多相關(guān)java properties文件內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論

和田市| 绥化市| 绥化市| 虞城县| 陕西省| 灌南县| 台江县| 突泉县| 从化市| 策勒县| 吴忠市| 灵丘县| 安新县| 香港| 泸定县| 扶风县| 手游| 松原市| 韶山市| 当涂县| 淳安县| 拜城县| 武陟县| 沙河市| 乌苏市| 璧山县| 资源县| 宜春市| 贵港市| 锡林郭勒盟| 民和| 股票| 开封市| 永济市| 天峨县| 浦江县| 巴中市| 迁安市| 吉安县| 宜兰市| 宁陵县|