java FILE类里为服务器路径,无法new成功

xumingjie1658 2013-04-12 08:39:54
在controller里想读入一个xml文件,该xml文件在服务器上地址为:
http://localhost:8088/Herbmes/include/navi/navi.xml
使用浏览器可以访问到该文件的,但是用
File XMLFile = new File("http://localhost:8088/Herbmes/include/navi/navi.xml");
时,调用判断XMLFile.exists(),该文件始终不存在。

有点郁闷。
...全文
567 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
xumingjie1658 2013-04-15
  • 打赏
  • 举报
回复
引用 2 楼 yktd26 的回复:
Java code?12345678URL oracle = new URL("http://www.oracle.com/"); BufferedReader in = new BufferedReader( new InputStreamReader(oracle.openStream())); String inputLi……
好的,我试试看。
xizhou704 2013-04-13
  • 打赏
  • 举报
回复
参考2楼!!
跳蚤图 2013-04-13
  • 打赏
  • 举报
回复
服务器上的文件 不能这样直接new 想查看有没有这个文件,有API的。
yktd26 2013-04-12
  • 打赏
  • 举报
回复

URL oracle = new URL("http://www.oracle.com/");
        BufferedReader in = new BufferedReader(
        new InputStreamReader(oracle.openStream()));

        String inputLine;
        while ((inputLine = in.readLine()) != null)
            System.out.println(inputLine);
        in.close();
这是官网上的一段
失落夏天 2013-04-12
  • 打赏
  • 举报
回复
new File(path); 这里输入的是物理地址路径啊。 就是D:\\test.txt 这样的路径,你输入的是url地址,当然不存在的。 你把这个url路径贴到我的电脑路径那里,你看看能打开么?

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧