JAVA中如何得到文件路径 |
您所在的位置:网站首页 › 怎么在java中创建文件 › JAVA中如何得到文件路径 |
JAVA 中如何得到文件路径
1. 如何获得当前文件路径
常用:
字符串类型: System.getProperty("user.dir");
综合:
package com.zcjl.test.base;
import java.io.File; public class Test {
public static void main(String[] args) throws Exception {
System.out.println(
Thread.currentThread().getContextClassLoader
().getResource(""));
System.out.println(Test.class.getClassLoader
().getResource(""));
System.out.println(ClassLoader.getSystemResource(""));
System.out.println(Test.class.getResource(""));
System.out.println(Test.class.getResource("/"));
System.out.println(new File("").getAbsolutePath());
System.out.println(System.getProperty("user.dir"));
} }
2.Web 服务中
(1).Weblogic
WebApplication 的系统文件根目录是你的 weblogic 安装所在根目录。
例如:如果你的 weblogic 安装在 c:\bea\weblogic700..... 那么,你的文件根路径就是 c:\. 所以,有两种方式能够让你访问你的服务器端的文件:
a. 使用绝对路径:
比如将你的参数文件放在 c:\yourconfig\yourconf.properties ,
直接使用
new FileInputStream("yourconfig/yourconf.properties"); b. 使用相对路径:
相对路径的根目录就是你的 webapplication 的根路径,即 WEB-INF 的上一级
目录,将你的参数文件放在 yourwebapp\yourconfig\yourconf.properties |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |