javasrc路徑怎麼寫
在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.war2: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/classesthis.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/classes3:Thread.currentThread().getContextClassLoader().getResource(".").getPath()Thread.currentThread().getContextClassLoader().getResource("").getPath() 得到的是 ClassPath的絕對URI路徑。
如:/D:/myProjects/hp/WebRoot/WEB-INF/classesThread.currentThread().getContextClassLoader().getResource("/").getPath() X 不 能運行最後在Web應用程序中,我們一般通過ServletContext.getRealPath("/")方法得到Web應用程序的根目錄的絕對路徑。還有request.getContextPath(); 在Weblogic中要用request.getServletContext().getContextPath();但如果打包成war部署到Weblogic服務器,項目內部並沒有文件結構的概念,用這種方式是始終得到null,獲取不到路徑,目前還沒有找到具體的解決方案。
2. Java:一個xml文件和src同級,應該如何寫路徑呢如果是用myeclipse的話(其它沒試過),new File(".").getAbsolutePath(),你會發現它就是你的工程目錄,src,xml都在這個目錄下,那麼xml自然就是 new File(xmlName)了。不過你做好的java程序肯定不能指望人家也用myeclipse來運行。。,所以給出兩個建義,
一。你仍然是new File(xmlName)來用這個xml,但是等你發佈做好的程序時,比如打成jar包,新個文件夾,比如test,把jar包和xml都放在裏面(即改成xml和jar包同級),這時你在test下執行jar包後,new File(xmlName)仍然是這個xml
二。把xml放到src目錄下,這時你獲取這個xml的輸入流就得這麼搞(Test類在哪個包無所謂)
InputStream input = Test.class.getClassLoader().getResourceAsStream("test.xml");
到時候如果打成jar包,這個xml就位於jar包的根目錄下。
-
創意花束男朋友特別有愛意的呢稱,創意花束男朋友暱稱特別
1、壓寨夫君、故事販賣機、不忍拋棄的小逗比、户口本第一頁。2、快到碗裏來、傲嬌小公主、大長腿歐巴、肩上風塵、男神大人撒浪嘿。3、男神大人撒浪嘿、最愛我的超人、你是我寶、我的男票、只酷不説帥。4、我男人、櫻桃小老頭、我的眼中僅有你、最愛我男神、宇...
-
舊傢俱怎樣變新
舊傢俱的更新主要有以下幾種情況:①作局部的修改加工,改變其使用功能。②改換貼面材料或油飾見新。③使用各類裝飾織物,掩蓋不足。其中以油漆的方式更新傢俱,增加其美觀的作法使用最多。將原有油漆從傢俱上清除的方法有三種。砂紙擦和熱脱的方法可清除普通油漆。...
-
很裝的語錄
其實你我都一樣,人人都在裝,關鍵是要裝像了,裝圓了,有一個門檻,裝成了就邁進去,成為傳説中的性情中人,沒裝好,就卡在那裏了。就是卡門。葉昊,我現在就想跟你説三個字,草泥馬,如果非要加個期限的話,我希望是一萬頭……有很多的時候,想對自己説,不裝強大會死嗎?卻又笑了!天上的星...
-
罪惡都市任務攻略是什麼
1、主流任務(大部分任務與過關有着必然的聯繫,有些雖沒有聯繫,但可以增加財產,提供免費槍支和車輛等)2、*TheParty*到換衣點換好衣服到達海邊的遊艇處參加晚會,駕車送Mercedes到PolePositionClub。報酬:1003、*BackAlleyBrawl*到MalibuClub找KentPaul瞭解情況後,到綠點...