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

熱點內容
澄海3c545地圖放到那個文件夾里 瀏覽:540
華為手機qq文件打開方式打開方式 瀏覽:856
手機如何刪除刪除不了的app 瀏覽:212
編程怎麼走好路 瀏覽:417
小米游戲數據一般在哪個文件 瀏覽:902
桌面伺服器是哪個文件 瀏覽:965
二進制數據類型的長度為什麼是n4 瀏覽:561
js獲取當前js文件的路徑 瀏覽:106
adobeindesigncs6教程 瀏覽:909
猿編程怎麼玩游戲 瀏覽:603
win8無網路訪問許可權 瀏覽:121
一個資料庫大小限制多少g 瀏覽:760
無限斯特拉托斯可以用哪些app看 瀏覽:954
圖片與拍攝文件大小名詞解釋 瀏覽:229
java的classpath配置文件 瀏覽:286
在小年魚app裡面如何退款 瀏覽:143
網路電話哪個軟體好用嗎 瀏覽:386
pokemon叫聲文件 瀏覽:689
工程源文件路徑 瀏覽:137
cad高版本能否打開低版本文件 瀏覽:430

友情鏈接