導航:首頁 > 文件教程 > 讀入配置文件時路徑

讀入配置文件時路徑

發布時間:2023-04-08 22:51:15

java讀取properties配置文件路徑問題

可以直接通過Thread方法直接獲取到項目路徑下的配置文件:
static {
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("BankConPort.properties"); //載入線程文件成為流
Properties prop = new Properties();
try {
prop.load(is);//直接轉換為對象
BOB_ReqURI = prop.getProperty("BOB_ReqURI");
BOB_SignURI = prop.getProperty("BOB_SignURI");
BOBLOGINPASSWORD = prop.getProperty("BOBLOGINPASSWORD");
} catch (IOException ex) {
java.util.logging.Logger.getLogger(BOBUtil.class.getName()).log(Level.SEVERE, null, ex);
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
Log.info("解析信息出錯", e.getMessage());

}
}
}
}

㈡ java 程序打包為jar發布後,讀取配置文件路徑出錯 ,怎樣獲取配置文件路徑

給你個例子,讀取config.properties文件。
文件內容(值自己加)如下:
TestHosts =
FormalHosts =

TestConfig =
FormalConfig =

HostsPath =
ConfigPath =

讀取文件的類如下:
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.*;

public class EvnConfig{
public static Properties PROPERTIES = new Properties();

static{
String proFilePath = System.getProperty("user.dir")+"/config.properties";
//System.out.println(proFilePath);
//InputStream propertiesStream = EvnConfig.class.getClassLoader().getResourceAsStream(proFilePath);
InputStream in = null;
try {
in = new BufferedInputStream(new FileInputStream(proFilePath));
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try{
PROPERTIES.load(in);
}catch(IOException e){
System.out.println("properties創建失敗!");
e.printStackTrace();
}
//System.out.println("EvnConfig.testHosts:"+PROPERTIES.getProperty("TestHosts"));
}

public static final String testHosts = changeCode(PROPERTIES.getProperty("TestHosts"));
public static final String formalHosts = changeCode(PROPERTIES.getProperty("FormalHosts"));
public static final String testConfig = changeCode(PROPERTIES.getProperty("TestConfig"));
public static final String formalConfig = changeCode(PROPERTIES.getProperty("FormalConfig"));
public static final String hostsPath = changeCode(PROPERTIES.getProperty("HostsPath"));
public static final String configPath = changeCode(PROPERTIES.getProperty("ConfigPath"));

public static String changeCode(String str){
String toStr = "";
try {
//System.out.println(str + "轉換...");
toStr = new String(str.getBytes("ISO-8859-1"),"GB2312");
//System.out.println(str + "轉換成功!");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
System.out.println(str + "轉換失敗!");
e.printStackTrace();
}
return toStr;

}
}

㈢ idea jvm option的配置文件的讀取路徑

在這個裡面的配置文件和讀取路徑的話是通過他的官方網站上去讀取的,你可以去他的優盤裡面去看一下。

㈣ cmd 運行jar包讀取配置文件時路徑報錯

你是怎麼打包的?手工用 WinRAR/WinZip/7Zip 之類的軟體打開這個 jar 文件確認一下,那個 xml 文件在什麼位置。

一般推薦的做法是把配置文件集中放在 /META-INF 文件夾中。

㈤ jar包中的類讀取配置文件的路徑問題,求大家幫幫忙

應該是直接就可以讀取的。

因為你的配置文件和Jar文件在同一個目錄下,如果你的應用能找到jar文件,也就是可以找到配置文件。不過你要在classpath路徑中添加*.properties。

閱讀全文

與讀入配置文件時路徑相關的資料

熱點內容
代碼百度地圖web服務api 瀏覽:523
什麼是和平營地app 瀏覽:624
智能ai機器人需要什麼編程 瀏覽:825
可控編程主要技術指標有哪些 瀏覽:271
數據分析回歸需要什麼條件 瀏覽:285
微信小程序按鈕顏色 瀏覽:69
長江大學網課用什麼app 瀏覽:431
華中系統圖紙編程哪個刀好 瀏覽:38
地方債務數據在哪裡查看 瀏覽:932
掃描文件怎麼設置格式 瀏覽:957
蘋果郵箱主機名填什麼 瀏覽:630
多張圖片同一個文件夾 瀏覽:798
win7怎麼打開shs文件 瀏覽:481
怎麼把文件夾做成iso 瀏覽:164
繽客網站上的房價怎麼在哪裡修改 瀏覽:406
單片機c51計數器實驗代碼 瀏覽:990
宏編程滑鼠代表什麼意思 瀏覽:753
別人撿到蘋果6有用嗎 瀏覽:829
word文件用wps打開 瀏覽:477
macbook修改文件格式軟體 瀏覽:757

友情鏈接