日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java 绝对路径_java 获取绝对路径

發布時間:2024/4/14 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java 绝对路径_java 获取绝对路径 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1、利用System.getProperty()函數獲取當前路徑:

System.out.println(System.getProperty("user.dir"));//user.dir指定了當前的路徑

2、使用File提供的函數獲取當前路徑:

File directory = new File("");//設定為當前文件夾

try{

System.out.println(directory.getCanonicalPath());//獲取標準的路徑

System.out.println(directory.getAbsolutePath());//獲取絕對路徑

}catch(Exceptin e){}

File.getCanonicalPath()和File.getAbsolutePath()大約只是對于new File(".")和new File("..")兩種路徑有所區別。

# 對于getCanonicalPath()函數,“."就表示當前的文件夾,而”..“則表示當前文件夾的上一級文件夾

# 對于getAbsolutePath()函數,則不管”.”、“..”,返回當前的路徑加上你在new File()時設定的路徑

# 至于getPath()函數,得到的只是你在new File()時設定的路徑

比如當前的路徑為 C:\test :

File directory = new File("abc");

directory.getCanonicalPath(); //得到的是C:\test\abc

directory.getAbsolutePath();?//得到的是C:\test\abc

direcotry.getPath();?//得到的是abc

File directory = new File(".");

directory.getCanonicalPath(); //得到的是C:\test

directory.getAbsolutePath();?//得到的是C:\test\.

direcotry.getPath();?//得到的是.

File directory = new File("..");

directory.getCanonicalPath(); //得到的是C:\

directory.getAbsolutePath();?//得到的是C:\test\..

direcotry.getPath();?//得到的是..

另外:System.getProperty()中的字符串參數如下:

System.getProperty()參數大全

# java.version?Java Runtime Environment version

# java.vendor?Java Runtime Environment vendor

# java.vendor.url?Java vendor URL

# java.home?Java installation directory

# java.vm.specification.version?Java Virtual Machine specification version

# java.vm.specification.vendor?Java Virtual Machine specification vendor

# java.vm.specification.name?Java Virtual Machine specification name

# java.vm.version?Java Virtual Machine implementation version

# java.vm.vendor?Java Virtual Machine implementation vendor

# java.vm.name?Java Virtual Machine implementation name

# java.specification.version?Java Runtime Environment specification version

# java.specification.vendor?Java Runtime Environment specification vendor

# java.specification.name?Java Runtime Environment specification name

# java.class.version?Java class format version number

# java.class.path?Java class path

# java.library.path?List of paths to search when loading libraries

# java.io.tmpdir?Default temp file path

# java.compiler?Name of JIT compiler to use

# java.ext.dirs?Path of extension directory or directories

# os.name?Operating system name

# os.arch?Operating system architecture

# os.version?Operating system version

# file.separator?File separator ("/" on UNIX)

# path.separator?Path separator (":" on UNIX)

# line.separator?Line separator ("\n" on UNIX)

# user.name?User's account name

# user.home?User's home directory

# user.dir?User's current working directory

tomcat下獲得項目的絕對路徑

private String projectName="sz_pro";?//?你項目的名稱

//獲取當前項目的絕對路徑

public String getPorjectPath(){

String nowpath;?//當前tomcat的bin目錄的路徑 如 D:\java\software\apache-tomcat-6.0.14\bin

String tempdir;

nowpath=System.getProperty("user.dir");

tempdir=nowpath.replace("bin", "webapps");?//把bin 文件夾變到 webapps文件里面

tempdir+="\\"+projectName;?//拼成D:\java\software\apache-tomcat-6.0.14\webapps\sz_pro

return tempdir;

}

總結

以上是生活随笔為你收集整理的java 绝对路径_java 获取绝对路径的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。