揭秘幾種java獲取當(dāng)前路徑的方法_JSP教程
教程Tag:暫無Tag,歡迎添加,賺取U幣!
推薦:解讀JSP中文字符亂碼處理的2種方法在編寫JSP程序時(shí),常常會(huì)碰到中文字符處理的問題,在接受request的中文字符時(shí)顯示出來一串亂碼。網(wǎng)上處理方法一籮筐,下面說說我用過的兩種有效地解決辦法: 1.為程序編寫一個(gè)字符串處理函數(shù),用一個(gè)靜態(tài)文件保存,在需要處理中文字符的JSP頁面中包含它, %!
1、利用System.getProperty()函數(shù)獲取當(dāng)前路徑:System.out.println(System.getProperty("user.dir"));//user.dir指定了當(dāng)前的路徑
2、使用File提供的函數(shù)獲取當(dāng)前路徑:
File directory = new File("");//設(shè)定為當(dāng)前文件夾
try{
System.out.println(directory.getCanonicalPath());//獲取標(biāo)準(zhǔn)的路徑
System.out.println(directory.getAbsolutePath());//獲取絕對(duì)路徑
}catch(Exceptin e){}
File.getCanonicalPath()和File.getAbsolutePath()大約只是對(duì)于new File(".")和new File("..")兩種路徑有所區(qū)別。
# 對(duì)于getCanonicalPath()函數(shù),“."就表示當(dāng)前的文件夾,而”..“則表示當(dāng)前文件夾的上一級(jí)文件夾
# 對(duì)于getAbsolutePath()函數(shù),則不管”.”、“..”,返回當(dāng)前的路徑加上你在new File()時(shí)設(shè)定的路徑
# 至于getPath()函數(shù),得到的只是你在new File()時(shí)設(shè)定的路徑
比如當(dāng)前的路徑為 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()中的字符串參數(shù)如下:
System.getProperty()參數(shù)大全
# 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
分享:淺析spring依賴注入的3種實(shí)現(xiàn)方式在講解依賴注入的3種實(shí)現(xiàn)方式之前,這里先澄清一下依賴注入的意義:讓組件依賴于抽象,當(dāng)組件要與其他實(shí)際對(duì)象發(fā)生依賴關(guān)系時(shí),通過抽象來注入依賴的實(shí)際對(duì)象。 依賴注入的3種實(shí)現(xiàn)方式分別是:接口注入(interfaceinjection)、Set注入(setterinjection)和
相關(guān)JSP教程:
- jsp response.sendRedirect不跳轉(zhuǎn)的原因分析及解決
- JSP指令元素(page指令/include指令/taglib指令)復(fù)習(xí)整理
- JSP腳本元素和注釋復(fù)習(xí)總結(jié)示例
- JSP FusionCharts Free顯示圖表 具體實(shí)現(xiàn)
- 網(wǎng)頁模板:關(guān)于jsp頁面使用jstl的異常分析
- JSP頁面中文傳遞參數(shù)使用escape編碼
- 基于jsp:included的使用與jsp:param亂碼的解決方法
- Java Web項(xiàng)目中連接Access數(shù)據(jù)庫的配置方法
- JDBC連接Access數(shù)據(jù)庫的幾種方式介紹
- 網(wǎng)站圖片路徑的問題:絕對(duì)路徑/虛擬路徑
- (jsp/html)網(wǎng)頁上嵌入播放器(常用播放器代碼整理)
- jsp下顯示中文文件名及絕對(duì)路徑下的圖片解決方法
- 相關(guān)鏈接:
- 教程說明:
JSP教程-揭秘幾種java獲取當(dāng)前路徑的方法
。