Topic: URL小问题,郁闷了很久了啊,哪位帮忙? |
Print this page |
1.URL小问题,郁闷了很久了啊,哪位帮忙? | Copy to clipboard |
Posted by: jfml Posted on: 2003-06-02 15:15 URL url = A.class.getResource("xmls/books.xml"); System.out.println(url); File f = new File("xmls/books.xml"); 上面这段程序得到的url为null,但是file.exists()返回true 郁闷了很久了啊 哪位帮助一下 谢谢 |
2.Re:URL小问题,郁闷了很久了啊,哪位帮忙? [Re: CrazyJavar] | Copy to clipboard |
Posted by: yakuu Posted on: 2003-06-02 16:27 URL url = A.class.getResource("xmls/books.xml"); is found by your classloader, it must be in your classpath, so, you can use URL url = A.class.getResource("/xmls/books.xml"); instead to find the file. please take a look at javadoc about getResource(String name); as far as File f = new File("xmls/books.xml"); it find your file use a abstract path. |
3.Re:URL小问题,郁闷了很久了啊,哪位帮忙? [Re: CrazyJavar] | Copy to clipboard |
Posted by: jfml Posted on: 2003-06-02 17:20 改成"/xmls/books.xml"以后 返回的url还是为null啊 请问这是为何? |
4.Re:URL小问题,郁闷了很久了啊,哪位帮忙? [Re: CrazyJavar] | Copy to clipboard |
Posted by: weichoon Posted on: 2003-06-03 22:56 make sure "/xmls/books.xml" appear in your classpath. |
5.Re:URL小问题,郁闷了很久了啊,哪位帮忙? [Re: CrazyJavar] | Copy to clipboard |
Posted by: jfml Posted on: 2003-06-04 09:34 也就是说要把xmls目录设定到project里的classpath么? |
6.Re:URL小问题,郁闷了很久了啊,哪位帮忙? [Re: CrazyJavar] | Copy to clipboard |
Posted by: jfml Posted on: 2003-06-04 09:38 还是不行啊 把xmls目录设定到classpath中后 还是同样的错误 郁闷啊 被这个问题烦了很久了啊 |
7.Re:URL小问题,郁闷了很久了啊,哪位帮忙? [Re: CrazyJavar] | Copy to clipboard |
Posted by: bean_wj Posted on: 2003-06-05 10:58 把xmls目录放到classes下,然后改成: java.net.URL url = WordProcessingTest.class.getResource("/xmls/books.xml"); System.out.println(url); File f = new File("xmls/books.xml"); System.out.println(f.exists()); 输出结果是: file:/D:/testProject/classes/xmls/books.xml false 另外,如果放在D:/testProject/xmls/books.xml,则f.exists()是true。 |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |