導航:首頁 > 編程語言 > java獲取提示框輸入的路徑

java獲取提示框輸入的路徑

發布時間:2023-08-31 13:11:38

『壹』 在java中怎麼獲取頁面的路徑

第一種:
File f = new File(this.getClass().getResource("/").getPath());
System.out.println(f);
結果:
C:Documents%20and%
獲取當前類的所在工程路徑;
如果不加「/」
File f = new File(this.getClass().getResource("").getPath());
System.out.println(f);
結果:
C:Documents%20and%comtest
獲取當前類的絕對路徑;
第二種:
File directory = new File("");//參數為空
String courseFile = directory.getCanonicalPath() ;
System.out.println(courseFile);
結果:
C:Documents and
獲取當前類的所在工程路徑;
第三種:
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
獲取當前工程路徑
第五種:
System.out.println( System.getProperty("java.class.path"));
結果:
C:Documents and bin

『貳』 在java中如何獲取文件夾路徑。類似在郵箱裡面那種上傳附件的形式,通過彈去對話框來選中文件夾來獲取。

web程序的話利用表單控制項file就可以獲取文件路徑了,後台利用文件流獲取文件

『叄』 Java應用程序怎樣點擊按鈕彈出文件查找路徑的窗口

1、js彈出文件選擇框:
給按鈕定義以下javascript函數:

var inputObj=document.createElement('input')
inputObj.setAttribute('id','_ef');
inputObj.setAttribute('type','file');
inputObj.setAttribute("style",'visibility:hidden');
document.body.appendChild(inputObj);
inputObj.click();
inputObj.value ;

單擊已經添加函數的按鈕會彈出選擇本地文件的對話框。
2、寫一個隱藏域, 當用戶選擇文件之後把圖片的路徑賦給這個隱藏域, 然後在action中就可以獲取到文件的路徑了,代碼如下:

function showRealPath(filePath){
document.getElementsByName("textfield")[0].value = filePath;
}
<input type="file" name="uploadfile" onfocus="showRealPath(this.value);"/>
<input type="hidden" name="uploadfileRealPath">

『肆』 Java獲取路徑的幾種方式

獲取當前類的絕對路徑;第1種:File directory = new File("");//參數為空
String courseFile = directory.getCanonicalPath() ;
System.out.println(courseFile);結果:C:\Documents and Settings\Administrator\workspace\projectName
獲取當前類的所在工程路徑;第2種: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文件的路徑第3種:System.out.println(System.getProperty("user.dir"));結果:C:\Documents and Settings\Administrator\workspace\projectName
獲取當前工程路徑第4種:System.out.println( System.getProperty("java.class.path"));結果:C:\Documents and Settings\Administrator\workspace\projectName\bin獲取當前工程路徑

閱讀全文

與java獲取提示框輸入的路徑相關的資料

熱點內容
ps3文件分割視頻 瀏覽:280
微信圖片一鍵轉發軟體 瀏覽:331
如何判斷s200plc編程電纜 瀏覽:691
太原編程培訓班哪個好 瀏覽:171
樹葉吹奏教程 瀏覽:6
社交app帶來了哪些社會問題 瀏覽:394
如何安裝愛寶8800數據採集器 瀏覽:712
文件保存了怎麼找不到了 瀏覽:476
彩票網站怎麼辨真假 瀏覽:840
pr找不到該文件 瀏覽:963
java移除panel 瀏覽:354
jsp填充jsp 瀏覽:166
海關外貿大數據在哪裡查 瀏覽:381
思特奇java筆試題 瀏覽:121
葫蘆俠在手機中的文件名 瀏覽:813
plc編程應該怎麼收錢 瀏覽:584
c語言中源文件由什麼組成 瀏覽:890
linuxhttpdphp配置文件 瀏覽:607
拆單數據要怎麼保存 瀏覽:17
mac電腦怎樣壓縮文件到100m 瀏覽:645

友情鏈接