
可以使用javalangSystem类的getProperty方法,传入参数"javahome"获得当前运行JVM的环境参数中的路径。
代码如下:
package comdusdcoding;public class Test01 {
public static void main(String[] args) {
String path = SystemgetProperty("javahome");
Systemoutprintln(path);
}
}
写了一个读取本地文件的方法, File file = new File(htmlFile); FileReader fr = new FileReader(file); BufferedReader br = new BufferedReader(fr); while((s=brreadLine())!=null){ aladd(s); } 在当前类写了main方法测试了一下是可行的, 但是页面某方法想调用该方法,不能实现。 总结问题是:只有放在static方法中可行,在其他地方调用都显示找不到指定文件。 文件结构: 把本地文件放在了web-inf的classes下了,相对路径写的(“/filetxt”); 求教为啥static方法可以,其他地方调用不行,这个函数本身不是静态的啊。
FileseparatorChar 返回一个字符,表示当前系统默认的文件名分隔符,在Windows中为"/",unix中为"/"。Fileseparator 与前者相同,但将分隔符作为字符串类型返回。pathSeparatorChar 返回一个字符,表示当前系统默认的路径名分隔符,在Windows中为";",unix中为":"。FilepathSeparator 与前者相同,但将分隔符作为字符串类型返回。import javalang;import javaio;public class test {public static void main(String[] args) {Systemoutprintln(FileseparatorChar);Systemoutprintln(Fileseparator);
以上就是关于如何获得Java应用程序的安装路径全部的内容,包括:如何获得Java应用程序的安装路径、java怎么获取本地文件路径、Java中如何获取系统路径等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)