File file = new File("路径名") 路径名的2种写法
项目的结构:相同颜色是同级的
bean的配置文件的读取和一般文件的读取有点差别的
public static void getValue(String key){ //传入"time"
Properties prop = new Properties();
Properties prop2 = new Properties();
Properties prop3 = new Properties();
//要么是全路径
File file = new File("D:\\java\\content\\eclipse-win64\\S\\java\\fd.properties");
//要么是去在全路径基础上去掉项目名
File file2 = new File("java\\fd.properties");
File file3 = new File("fd2.properties");
try {
//装载配置文件
prop.load(new FileInputStream(file));
prop2.load(new FileInputStream(file2));
prop3.load(new FileInputStream(file3)); } catch (IOException e) {
e.printStackTrace();
}
//返回获取的值
System.out.println(prop.getProperty(key)
+ prop2.getProperty(key)+prop3.getProperty(key));
}
8 8 9
fd.properties的内容
项目名是 S
点开bin文件夹
注意这个fd.properties文件
发现:
只有在src或者java文件夹下的java文件或资源文件才会编译,然后通过打包,会复制到commlib中
后面有2个ok
/*
1.绝对路径 a.带盘符,如E:/book.xml b.以http开头,http://img.baidu.com/img/book.jpg 2.相对路径 a.带"/"开头,如/book.xml b.不带"/"开头,如book.xml 现在项目结构如下,在ParseXML类中操作,我实验项目System.getProperty("user.dir")=E:\ProjectTest\javaEE\ 绝对路径: new
File("E:/ProjectTest/javaEE/src/com/ly/javaee/xml/dom4j/book.xml")---OK 相对路径 new
File("book.xml")----报错(此时相当于System.getProperty("user.dir")+"book.xml",这是文件book.xml不存在user.dir下面) new File("src/com/ly/javaee/xml/dom4j/book.xml")----OK(不带"/"
可见在项目中相对的是以项目名为根路径,此时相当于System.getProperty("user.dir")+"src/com/ly/javaee/xml/dom4j/book.xml") new File("/book.xml")----以下可以看出本JVM运行在E盘下,此时带"/"就相当于"E:/book.xml",JVM运行在哪个盘符就以哪个为根路径 new
File("./book.xml");---报错(同new File("book.xml")效果)
File file = new File("路径名") 路径名的2种写法的更多相关文章
- 【翻译自mos文章】对于每个文件的 file.id and file.incarnation number,重命名文件别名
对于每个文件的 file.id and file.incarnation number,重命名文件别名 參考原文: Rename Alias of Datafile as Per file.id an ...
- File.createNewFile和 File.createTempFile比较和区别
原文地址:http://wzhiju.iteye.com/blog/1119037 最近,在看代码时看到了一个方法, File.createTempFile() ,由此联想到File.createNe ...
- python3: error while loading shared libraries: libpython3.5m.so.1.0: cannot open shared object file: No such file or directory
安装python3遇到报错: wget https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tgz ./configure --prefix=/u ...
- 安卓开发error opening trace file: No such file or directory (2)报错原因
error opening trace file: No such file or directory (2) 这个问题的出现是因为运行的测试机android系统版本和项目api不一致导致. 改成一样 ...
- error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
zabbix3.2启动有如下报错: # service zabbix_server startStarting zabbix_server: /home/zabbix-server/sbin/zab ...
- 错误解决:error while loading shared libraries: libcurl.so.4: cannot open shared object file: No such file or directory
执行以下代码,生成唯一的UID $fp = popen("/xxx/bin/tools/uuidgen system", "r");// $uid = frea ...
- 【转】error while loading shared libraries: libevent-2.0.so.5: cannot open shared object file: No such file or directory
错误信息: /usr/local/memcacheq/bin/memcacheq: error while loading shared libraries: libevent-2.0.so.5: c ...
- 解决openssl: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory错误
问题 在Centos7上编译安装openssl后,运行openssl version出现如下错误: openssl: error while loading shared libraries: lib ...
- NopCommerce 发布时 Could not load file or assembly 'file:///...\Autofac.3.5.2\lib\net40\Autofac.dll' or one of its dependencies
本文转自:http://www.nopcommerce.com/boards/t/33637/4-errors.aspx 问题: The 3.5 solution compiles fine, and ...
随机推荐
- nginx:负载均衡实战(一)
1.负载均衡说明 2.准备 我自己在电脑布置了两台虚拟机,两台都有nginx和tomcat,两台虚拟机布置的ip分别是37以及54,我在tomcat的首页动了点手脚,方便自己看是来自哪个ip的 接着在 ...
- js上传文件(可自定义进度条)
//本地上传图片.语音 function rsc_UploadFile(file) { ]; //创建一个FormData空对象,然后使用append方法添加key/value var fd = ne ...
- nginx 隐藏nginx版本号
为什么要隐藏 Nginx 版本号:一般来说,软件的漏洞都与版本有关,隐藏版本号是为了防止恶意用户利用软件漏洞进行攻击 worker_processes 1; events { worker_conne ...
- Nginx部署vue多项目
server { listen 80; server_name test.hehe.com; location /riskcontrol { root /data; try_files $uri $u ...
- Delphi 10.3终于来了
http://altd.embarcadero.com/download/radstudio/10.3/delphicbuilder10_3_0_94364.iso 安装工具: http://ww ...
- 搭建VUE项目
1.换源由于npm源服务器在国内访问速度较慢,所以一般需要更换源服务器地址npm config set registry https://registry.npm.taobao.org也可以安装cnp ...
- HDU 6090 17多校5 Rikka with Graph(思维简单题)
Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he ...
- iOS原生和React-Native之间的交互1
今天,记录一下iOS原生和React-Native之间的交互.如果第一次接触最好先移步至 http://www.cnblogs.com/shaoting/p/6388502.html 先看一下怎么在i ...
- 【Python】基础练习题-1
#练习1:从键盘输入两个数,并比较其大小,直到输入e/E退出程序 while 1: input_number=raw_inut("please input two numbers,enter ...
- table中head表头固定,body滚动
<style type="text/css"> .table-head { background-color: #; color: #; } .table-body { ...