我想得到当前运行的.class的本地路径并向其中写入文件,用了
getClass().getResource("/my/contacteditor/images/")返回了一个URL,
得到的path是这样:/E:/NetBeans%206.1%20FINAL/ContactEditor/build/classes/my/contacteditor/images/
然而根本不能往里面写东西,怎么样才能得到这个路径:
E:/NetBeans FINAL/ContactEditor/build/classes/my/contacteditor/images/
其中, .class文件存放于E:/NetBeans FINAL/ContactEditor/build/classes/my/contacteditor/

解决方案 »

  1.   

    http://blog.csdn.net/sunyujia/archive/2008/09/21/2957481.aspx
      

  2.   

    http://topic.csdn.net/u/20080520/21/1dc25316-8316-46f8-904b-ded9c4b7587a.html
    还有,慢慢看
      

  3.   

    URL 可以转换为file toURI 然后就可以new File(uri)了
      

  4.   

    我习惯使用jar文件的时候才用class加载的相对路径。
      

  5.   

    路径是得到了:D:\Eclipse\Eclipse%20Projects\ManyTest\bin\dxm
    可是,Eclipse%20Projects中间的空格怎么变成 %20 了??如何变回空格?
      

  6.   

        /** 
         * 
         * Description:同getClassFile 解决中文编码问题 
         * 
         * @param clazz 
         * @return 
         * @mail [email protected] 
         * @since:Sep 21, 2008 1:10:12 PM 
         */ 
        public static String getClassFilePath(Class clazz) { 
            try { 
                return java.net.URLDecoder.decode(getClassFile(clazz) 
                        .getAbsolutePath(), "UTF-8"); 
            } catch (UnsupportedEncodingException e) { 
                e.printStackTrace(); 
                return ""; 
            } 
        } 
    原文网址:http://blog.csdn.net/sunyujia/archive/2008/09/21/2957481.aspx
    我给你的 地址里面有,要细看。
      

  7.   

    谢谢二位,问题搞定.特别感谢sunyujia,今日受益颇多,呵呵,不说了,接分!