java learnging

          一塊探討JAVA的奧妙吧
          posts - 34, comments - 27, trackbacks - 0, articles - 22

          文件路徑的操作

          Posted on 2005-04-15 13:57 bigseal 閱讀(343) 評論(0)  編輯  收藏

              看一些開源代碼的時候發展自己對關于文件路徑的操作的使用不甚理解,就把它們放到一塊對比著看一下。

          import java.io.IOException;
          import java.net.URL;

          /**
           * @author Administrator
           * @version 1.0
           * 
           * TODO
           
          */

          public class Simple {

              
          public static void main(String[] args) {
                  
                  System.
          out.println("getResource");

                  System.
          out.println(Simple.class.getResource(""));
                  System.
          out.println(Simple.class.getResource("."));
                  System.
          out.println(Simple.class.getResource("/"));
                  System.
          out.println(Simple.class.getResource("/images/About.gif"));
                  System.
          out.println(Simple.class.getResource("images/About.gif"));
                  
                  System.
          out.println("getAbsolutePath:");
                  
                  System.
          out.println(new File("").getAbsolutePath());
                  System.
          out.println(new File(".").getAbsolutePath());
                  System.
          out.println(new File("/").getAbsolutePath());
                  System.
          out.println(new File("images/About.gif").getAbsolutePath());
                  System.
          out.println(new File("/images/About.gif").getAbsolutePath());
                  
              }

          }
          這是在eclipse中顯示的運行結果
          getResource
          file:/D:/software/eclipse%203.0.1/workspace/simple/bin/simple/
          file:/D:/software/eclipse%203.0.1/workspace/simple/bin/simple/
          file:/D:/software/eclipse%203.0.1/workspace/simple/j2src/
          file:/D:/software/eclipse%203.0.1/workspace/simple/bin/images/About.gif
          null
          getAbsolutePath:
          D:\software\eclipse 3.0.1\workspace\simple
          D:\software\eclipse 3.0.1\workspace\simple\.
          D:\
          D:\software\eclipse 3.0.1\workspace\simple\images\About.gif
          D:\images\About.gif
          這是在命令行下運行class文件的結果
          getResource
          file:/D:/software/eclipse%203.0.1/workspace/simple/bin/simple/
          file:/D:/software/eclipse%203.0.1/workspace/simple/bin/simple/
          file:/D:/software/eclipse%203.0.1/workspace/simple/bin/
          file:/D:/software/eclipse%203.0.1/workspace/simple/bin/images/About.gif
          null
          getAbsolutePath:
          D:\software\eclipse 3.0.1\workspace\simple\bin
          D:\software\eclipse 3.0.1\workspace\simple\bin\.
          D:\
          D:\software\eclipse 3.0.1\workspace\simple\bin\images\About.gif
          D:\images\About.gif
          這是項目的文件夾結構
          simple 
                ├─bin
                │  ├─images
                │  └─simple
                └─src
                      ├─images
                      └─simple
          可以看到有時候分別在elipse運行和命令行class文件得到的文件路徑是不一樣的。
          不知道為什么會出現這中情況呢?

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 宜君县| 枞阳县| 乳源| 惠安县| 吕梁市| 杭锦后旗| 滦平县| 罗源县| 丘北县| 都安| 抚顺市| 南靖县| 绩溪县| 建宁县| 嵊泗县| 西畴县| 丰顺县| 曲沃县| 科尔| 博乐市| 久治县| 石屏县| 镇安县| 涪陵区| 涡阳县| 杂多县| 望谟县| 大庆市| 永清县| 大埔县| 屯留县| 醴陵市| 昌平区| 沙坪坝区| 根河市| 密山市| 江山市| 巴南区| 达州市| 哈巴河县| 耿马|