導航:首頁 > 編程語言 > 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獲取提示框輸入的路徑相關的資料

熱點內容
哪些統計量可以反映數據波動 瀏覽:946
js地圖標記怎麼清空 瀏覽:479
googlenow教程 瀏覽:508
安全四個責任體系內容文件 瀏覽:965
南陽政務app怎麼注冊 瀏覽:343
照片壓縮包同一路徑的文件能刪嗎 瀏覽:590
路由沒網路怎麼辦 瀏覽:745
南京網站推廣大概多少錢 瀏覽:983
js隱藏列印出來 瀏覽:135
手工之家app哪裡下載 瀏覽:328
網路教育聯盟英語考試是什麼 瀏覽:69
macairwin10忘記密碼 瀏覽:716
java上傳方法 瀏覽:970
csc文件夾可以刪除嗎 瀏覽:130
打線工具怎麼用 瀏覽:376
mat文件如何轉換為cad 瀏覽:761
qq瀏覽器舊版本614 瀏覽:713
將資料庫文件批量導出excel 瀏覽:262
招投標文件在招標公司存多少年 瀏覽:551
u盤空間不足不能復制系統鏡像文件 瀏覽:212

友情鏈接