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

熱點內容
ug編程初始化怎麼辦 瀏覽:295
nginxajax配置文件 瀏覽:467
小程序獲取二進制圖片 瀏覽:206
為什麼有的數控車編程有百分號 瀏覽:425
m文件有什麼用 瀏覽:359
宜昌做投標文件多少錢 瀏覽:166
uc瀏覽器小說下載那個文件夾 瀏覽:908
qq和手機 瀏覽:238
ps備份文件教程 瀏覽:306
資料庫原理嵌套查詢 瀏覽:679
為什麼文件只解壓了一部分 瀏覽:728
c語言課程教學視頻java源碼下載 瀏覽:444
老毛桃2014u盤啟動盤製作教程 瀏覽:53
盜取qq密碼視頻教程 瀏覽:948
win10有幾個g 瀏覽:890
51單片機程序寫入 瀏覽:387
cad圖形出現寫入關閉文件出錯 瀏覽:643
唱吧錄的歌在哪個文件夾 瀏覽:576
采樣碼用什麼app掃描 瀏覽:339
word如何統計行數 瀏覽:485

友情鏈接