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 ...
随机推荐
- Docker容器使用jenkins部署web项目--总结(二)
(1)需要安装Docker容器,在Docker容器内安装jenkins,gogs,tomcat. 新建maven项目,添加findbugs plugin. 使用docker启动jenkins,go ...
- java中的package
java中用于存放源文件的文件夹叫做包package package中可以有源文件也可以由其他包. package的“全限定名”不是从磁盘的根目录开始的,而是从源代码的根目录开始的,以点号“.”作为分 ...
- Ubuntu server 网络配置中遇到的问题
Ubuntu server 网络配置中遇到的问题 图片中ip地址有可能和文字不符,请不要在意太多,知道原理即可 - 1.首先就是要配置ip地址 vim /etc/network/interfaces ...
- Linux3.10.0块IO子系统流程(1)-- 上层提交请求
Linux通用块层提供给上层的接口函数是submit_bio.上层在构造好bio之后,调用submit_bio提交给通用块层处理. submit_bio函数如下: void submit_bi ...
- Linux系统分区方案(CentOs 6)
装Linux如何分区: 方案1:(监控服务器,负载均衡器) 1./boot 引导分区,存放引导文件和Linux内核. 启动文件:用于判断你需要启动哪个操作系统或启动哪个内核. ...
- ui-router ng-router
开发中常用ui-router来设置路由: ui-router使用很简单,延续了之前ngRoute的特点. 1.首先得注入ui.router模块. 接下来就是简单的配置 2.$stateProvider ...
- 人生苦短,我用python,为什么选择python,python简介
认识 Python 人生苦短,我用 Python —— Life is short, you need Python  目标 Python 的起源 为什么要用 Python? Python 的特点 ...
- springboot 打包部署
springboot内置有tomcat所以我们测试的时候没有加入自己的容器 那么我们的 springboot 怎么发布呢? 1.打成 jar 2.打成 war 这种方式我就不说了,网上有教程,我觉得j ...
- wait_activity
wait_activity(self, activity, timeout, interval=1): android特有的 返回的True 或 False :Agrs: - activity - 需 ...
- ESP8266 上线
1.首先配置esp8266 WIFI模块 使用USB转 TTL 连接 esp8266 WIFI模块,波特率115200 //查询固件版本 AT+GMR //设置WiFi应用模式为Station AT+ ...