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

熱點內容
網路中常用的傳輸介質 瀏覽:518
文件如何使用 瀏覽:322
同步推密碼找回 瀏覽:865
樂高怎麼才能用電腦編程序 瀏覽:65
本機qq文件為什麼找不到 瀏覽:264
安卓qq空間免升級 瀏覽:490
linux如何刪除模塊驅動程序 瀏覽:193
at89c51c程序 瀏覽:329
怎麼創建word大綱文件 瀏覽:622
裊裊朗誦文件生成器 瀏覽:626
1054件文件是多少gb 瀏覽:371
高州禁養區內能養豬多少頭的文件 瀏覽:927
win8ico文件 瀏覽:949
仁和數控怎麼編程 瀏覽:381
項目文件夾圖片 瀏覽:87
怎麼在東芝電視安裝app 瀏覽:954
plc顯示數字怎麼編程 瀏覽:439
如何辨別假網站 瀏覽:711
寬頻用別人的賬號密碼 瀏覽:556
新app如何佔有市場 瀏覽:42

友情鏈接