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

熱點內容
ipd編譯要求 瀏覽:931
壓縮解壓王怎麼用 瀏覽:29
伺服器共享文件如何備份 瀏覽:752
買安卓手機怎麼在官網買 瀏覽:120
詩詞入門PDF 瀏覽:361
毒app是什麼單位 瀏覽:64
如何自己編譯android系統 瀏覽:792
phpmysqlpdomysqli 瀏覽:808
php修改sql語句 瀏覽:720
android有道api 瀏覽:387
撓耳營水表用的什麼app 瀏覽:54
戰錘40kpdf 瀏覽:381
java判斷字元串是漢字 瀏覽:468
2017初級教材pdf 瀏覽:457
松下空調壓縮機品牌 瀏覽:823
python復選框 瀏覽:752
反詐中心app是什麼時候出來的 瀏覽:592
魔獸世界需要什麼伺服器地址 瀏覽:195
啥是單片機休眠 瀏覽:110
什麼音樂app最好 瀏覽:933