可将URL转成绝对路径不就可以了吗?

解决方案 »

  1.   


    url = new URL("http://www.uestc.edu.cn/templates/index2k2");
    File dirFile = new File(url.getPath());
    dirFile.list();
      

  2.   

    我使用过的,但它把dirFile当成本地文件,假如我的程序在h:\java,他把dirFile的路径当成是h:\java\www.uestc.edu.cn\templates\index2k2,真是不爽
      

  3.   

    我给你写了这些,在允许目录检索的机器上可以看到相对路径的内容
    但是我不明白你为什么要这样做,你得到相对路径毫无用处,而且大多数情况下,一个web服务器很少允许你去列他的目录
    import java.io.*;
    import java.net.*;
     
    class TTT
    {
    public static void main(String s[])
    {
    URL url = null;
    try
    {
    url = new URL("http://www.uestc.edu.cn/templates/index2k2");
    }
    catch (Exception e)
    {
    }
    File dirFile = new File(url.getFile());
    String dir[] = dirFile.list();
    System.out.println("File(s) under " + url.getFile() + " : ");
    for(int i=0; i<s.length; i++)
    System.out.println(s[i]);
    }
    };
      

  4.   

    我再试试,我记得好像他会把路径当成是h:\java\www.uestc.edu.cn\templates\index2k2,
    其中该程序在h:\java下