导航:首页 > 文件教程 > 读入配置文件时路径

读入配置文件时路径

发布时间: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。

阅读全文

与读入配置文件时路径相关的资料

热点内容
ps6路径选择工具 浏览:955
视频文件损坏返回不了 浏览:656
如何判断网络被降速了 浏览:676
ps做成图片后怎么弄成文件 浏览:689
左侧导航栏css代码 浏览:952
钉钉传送文件最大多少兆 浏览:126
app下载哪里最全 浏览:599
word如何画大箭头 浏览:245
word批量转pdf工具21注册机 浏览:546
打印文档文件3000字需要多少钱 浏览:239
泊车助手app 浏览:147
pscs6完全自学教程 浏览:461
文件夹去不掉只读属性 浏览:203
qq怎么接收文件夹 浏览:35
javahashmapvalues 浏览:548
鼠标选定不了文件内容是坏了么 浏览:589
打开excel标准模板文件名 浏览:798
该文件名字不包含扩展名 浏览:565
华为备份文件 浏览:368
批量删除cpp文件代码注释的工具 浏览:312

友情链接