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

讀入配置文件時路徑

發布時間: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。

閱讀全文

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

熱點內容
windows7系統共享文件 瀏覽:62
ps前往文件夾 瀏覽:694
信捷plc編程用哪個軟體 瀏覽:939
vba導入文件 瀏覽:690
更新後版本英文怎麼說 瀏覽:267
桌面雲配置文件分離 瀏覽:505
iphone5如何升級4g網路 瀏覽:5
團購是在哪個app 瀏覽:897
打開多個word文檔圖片就不能顯示 瀏覽:855
騰訊新聞怎麼切換版本 瀏覽:269
app安裝失敗用不了 瀏覽:326
桌面文件滑鼠點開會變大變小 瀏覽:536
手機誤刪系統文件開不了機 瀏覽:883
微信兔子甩耳朵 瀏覽:998
android藍牙傳文件在哪裡 瀏覽:354
蘋果6s軟解是真的嗎 瀏覽:310
c語言代碼量大 瀏覽:874
最新網路衛星導航如何使用 瀏覽:425
以下哪些文件屬於圖像文件 瀏覽:774
zycommentjs 瀏覽:414

友情鏈接