1. 获取用户目录路径:
String userHome= System.getProperty("user.home");
1.1字符串替换:
String str=
new StringBuilder(String.valueOf(this.userHome)).append("quest.db").toString();
String URL="jdbc:sqlite:/+new File(str).getAbsolutePath().replaceAll("\\\\","/");
2. 即:工程根目
System.getProperty("user.dir")
3. 获取java项目中资源的相对路径:
System.loadLibrary("buslib4j");//可以放在任何java.library.path包含的路径中。
System.load(System.getProperty("user.dir")+"/DLL/buslib4j.dll");
String CONFIGURE_SERVICE="/serviceIp.properties";
String filePath= System.getProperty("user.dir")+this.CONFIGURE_SERVICE;
5. 配置文件
String srcPath = System.getProperty("user.dir")+/serviceIp.properties;
File file=new File(srcPath);
5.File file=new File("name.txt")中name文件应在何目录下?
和你的该句代码所在文件同一目录下就可以了。若放其他目录下
private String
CONFIGURE_LOCATION= "/module_view.properties"; /**
前面有 “ / ”代表了工程的根目录,说明该文件在该工程的根目录下。 */
说明:
System.getProperty("user.home") |
本机的用户目录,如:C:\Users\jpt |
File.separator |
目录分隔符, / |
new File("quest.db") |
新建一个文件,文件名quest.db
|
propertiesTest.class.getResourceAsStream("/module_view.properties"); 前面有 “ / ”代表了工程的根目录下,说明该文件路径:从该工程的根目录下开始。
| |
.. | |
./ |
当前目录下 |
/ |
工程的根目录下 |
.properties |
Properties prop = new Properties(); InputStream inStream = Main.class.getResourceAsStream( this.CONFIGURE_LOCATION); prop.load(inStream); Set keyValue = prop.keySet(); for (Iterator it = keyValue.iterator(); it.hasNext();) { String key = (String) it.next(); String values= prop.getProperty(key); System.err.println( key+" : "+ values); classSet.add( values ); } |
.txt |
一行一行写入; 才能一行一行读取。
|
.xml |
XmlDocument类 按标签节点读取内容。(可做小型数据库使用) c#
|