搜尋此網誌

2013年9月4日 星期三

【Java】使用者設定檔路徑(User Shell Folder)

有了這個就可以輕鬆取得使用者相關資料夾的相對路徑,不用因為設了絕對路徑,換一台電腦操作,因為使用者名稱不同,導致檔案路徑不同,造成找不到檔案的窘境。


Java 6 up
透過System.getProperty(string key)取得使用者系統資訊,以下參數用法參考至Java 7說明文件
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

C# or Windows Environment
以下參考至User Shell Folder
%USERPROFILE%\Desktop     Desktop
%USERPROFILE%\Start Menu\Programs   Programs
%USERPROFILE%\My Documents            My Documents 

沒有留言: