您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

java中获取文件或文件夹的路径方法

2025/4/29 17:07:46发布8次查看
获取当前类的所在工程路径; 如果不加“/” file f = new file(this.getclass().getresource("").getpath()); system.out.println(f); 结果:c:\documents%20and%20settings\administrator\workspace\projectname\bin\com\test 获取当前类的绝对路径; 第二种:file directory = new file("");//参数为空 string coursefile = directory.getcanonicalpath() ; system.out.println(coursefile); 结果:c:\documents and settings\administrator\workspace\projectname 获取当前类的所在工程路径; 第三种:url xmlpath = this.getclass().getclassloader().getresource("selected.txt"); system.out.println(xmlpath); 结果:file:/c:/documents%20and%20settings/administrator/workspace/projectname/bin/selected.txt 获取当前工程src目录下selected.txt文件的路径 第四种:system.out.println(system.getproperty("user.dir")); 结果:c:\documents and settings\administrator\workspace\projectname 获取当前工程路径第五种:system.out.println( system.getproperty("java.class.path")); 结果:c:\documents and settings\administrator\workspace\projectname\bin 获取当前工程路径
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product