導航:首頁 > 編程語言 > 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的源文件的路徑相關的資料

熱點內容
胸7椎體輕度壓縮 瀏覽:108
sk5伺服器什麼意思 瀏覽:554
什麼是廊坊交警app 瀏覽:294
衣櫃造價演算法 瀏覽:984
默認的web伺服器地址 瀏覽:694
單片機與發光二極體 瀏覽:320
pythonwebmodule 瀏覽:328
空調壓縮機不停了 瀏覽:115
python序列怎麼取 瀏覽:199
線上資料庫加密怎麼查詢 瀏覽:794
js中數據加密 瀏覽:470
穴pdf 瀏覽:548
阿里雲伺服器雲資料庫還需要嗎 瀏覽:146
在程序設計中常用的演算法有哪些 瀏覽:977
為什麼蘇州公積金app一直維護 瀏覽:805
有ip地址但是dhcp伺服器 瀏覽:446
三星手機加密中斷怎麼回事 瀏覽:538
訓練模型init源碼 瀏覽:840
程序編譯是誰的功能 瀏覽:505
qq收藏怎樣設置加密 瀏覽:291