導航:首頁 > 編程語言 > java的源文件的路徑

java的源文件的路徑

發布時間:2025-01-03 22:00:20

『壹』 java源文件編譯時要放在哪裡

很可能是編譯的路徑沒選對,用絕對路徑也可以,用相對路徑也可以,絕對路徑:就是cmd調出管理員窗口後,輸入javac E:\xuexi\HelloWord.java。其中E:\xuexi\HelloWord.java就是源程序HelloWord.java的絕對路徑,即源程序文件在哪裡,它的絕對路徑就是從類似上述例子的路徑。相對路徑:一直點一直點,找到你寫的源文件HelloWord.java,然後在最上面路徑那一欄中把原來的名字全部刪掉,輸入cmd,這就是相對路徑。例如HelloWord.java在E:\xuexi下,只需要把最上面路徑欄里的E:\xuexi刪掉,換成cmd回車就可以了,最後再輸入javac HelloWord.java就可以編譯。如果有錯誤也會報錯。

『貳』 本人初學Java,我用eclipse編寫的代碼文件保存位置在哪裡

就在你所新建的工程目錄下,打開eclipse右鍵所建項目,點擊最底下的屬性,找到location後面的路徑就是你的項目路徑,這樣就可以從該項目的src目錄下找到你寫的源文件了

『叄』 java讀取文件路徑問題

在java中獲得文件的路徑在我們做上傳文件操作時是不可避免的。

web 上運行
1:
this.getClass().getClassLoader().getResource("/").getPath();
this.getClass().getClassLoader().getResource("").getPath(); 得到的是 ClassPath的絕對URI路徑。
如:/D:/jboss-4.2.2.GA/server/default/deploy/hp.war/WEB-INF/classes/
System.getProperty("user.dir");
this.getClass().getClassLoader().getResource(".").getPath(); 得到的是 項目的絕對路徑。
如:/D:/jboss-4.2.2.GA/server/default/deploy/hp.war

2:
this.getClass().getResource("/").getPath();
this.getClass().getResource("").getPath(); 得到的是當前類 文件的URI目錄。不包括自己!
如:/D:/jboss-4.2.2.GA/server/default/deploy/hp.war/WEB-INF/classes/com/jebel/helper/
this.getClass().getResource(".").getPath(); X 不 能運行

3:
Thread.currentThread().getContextClassLoader().getResource("/").getPath()
Thread.currentThread().getContextClassLoader().getResource("").getPath() 得到的是 ClassPath的絕對URI路徑。
如:/D:/jboss-4.2.2.GA/server/default/deploy/hp.war/WEB-INF/classes/
Thread.currentThread().getContextClassLoader().getResource(".").getPath() 得到的是 項目的絕對路徑。
如:/D:/jboss-4.2.2.GA/server/default/deploy/hp.war

在本地運行中
1:
this.getClass().getClassLoader().getResource("").getPath();
this.getClass().getClassLoader().getResource(".").getPath(); 得到的是 ClassPath的絕對URI路徑。
如:/D:/myProjects/hp/WebRoot/WEB-INF/classes
this.getClass().getClassLoader().getResource(".").getPath(); X 不 能運行
2:
this.getClass().getResource("").getPath();
this.getClass().getResource(".").getPath(); 得到的是當前類 文件的URI目錄。不包括自己!
如:/D:/myProjects/hp/WebRoot/WEB-INF/classes/com/jebel/helper/
/D:/myProjects/hp/WebRoot/WEB-INF/classes/ 得到的是 ClassPath的絕對URI路徑。
如:/D:/myProjects/hp/WebRoot/WEB-INF/classes

3:
Thread.currentThread().getContextClassLoader().getResource(".").getPath()
Thread.currentThread().getContextClassLoader().getResource("").getPath() 得到的是 ClassPath的絕對URI路徑。。
如:/D:/myProjects/hp/WebRoot/WEB-INF/classes
Thread.currentThread().getContextClassLoader().getResource("/").getPath() X 不 能運行

最後
在Web應用程序中,我們一般通過ServletContext.getRealPath("/")方法得到Web應用程序的根目錄的絕對路徑。
還有request.getContextPath(); 在Weblogic中要用request.getServletContext().getContextPath();但如果打包成war部署到Weblogic伺服器,項目內部並沒有文件結構的概念,用這種方式是始終得到null,獲取不到路徑,目前還沒有找到具體的解決方案。

閱讀全文

與java的源文件的路徑相關的資料

熱點內容
php按鈕點擊事件 瀏覽:934
河南伺服器機房售後服務雲主機 瀏覽:184
android仿聯系人 瀏覽:368
什麼app軟體可以學音標 瀏覽:669
郭天祥十天學會單片機優酷 瀏覽:330
什麼app兒童免費 瀏覽:582
遺傳演算法的理解 瀏覽:800
php刪除sql 瀏覽:841
紅進藍出指標源碼 瀏覽:700
python數據轉換列表類型 瀏覽:717
解壓後的文件怎麼解開 瀏覽:175
四川補貼認證下載什麼app 瀏覽:858
android設計風格 瀏覽:426
視頻不支持我的加密 瀏覽:342
布包pdf 瀏覽:267
程序員錄制課程表 瀏覽:626
eclipsephp斷點調試 瀏覽:895
虛擬成交量指標源碼 瀏覽:838
什麼APP有背單詞小組 瀏覽:43
蘋果2g視頻怎麼加密 瀏覽:204