java learnging

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

          文件路徑的操作

          Posted on 2005-04-15 13:57 bigseal 閱讀(341) 評論(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文件得到的文件路徑是不一樣的。
          不知道為什么會出現這中情況呢?

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


          網站導航:
           
          主站蜘蛛池模板: 兴和县| 高雄县| 吉林市| 衡山县| 乌拉特前旗| 遂昌县| 崇阳县| 墨脱县| 瓮安县| 称多县| 库尔勒市| 文安县| 海门市| 朝阳区| 莫力| 隆回县| 吉水县| 阿拉尔市| 墨竹工卡县| 雅安市| 江山市| 彭阳县| 梅河口市| 哈密市| 虎林市| 延津县| 呼和浩特市| 南华县| 金寨县| 许昌县| 旬邑县| 台中市| 岢岚县| 乌兰浩特市| 渭南市| 大理市| 古浪县| 连平县| 新密市| 濮阳县| 富锦市|