DefaultMutableTreeNode 为一个数组textArea 可以为别的这个主要是左边一个树,右边是 textArea 的情况,jsp可以参考一下public void Explorer2(DefaultMutableTreeNode p)   //检测目录的最好方法        {          p.removeAllChildren();    //关键的修改处,如果没有这一句,就会出现两次或多次加载同一节点的现象        try{                        File path = (File)p.getUserObject();                        String[] list = path.list();                        for(int i = 0; i<list.length;i++)                        {                                File NotKnown = new File(path + "\\" + list[i]);                                if(NotKnown.isFile())                                {                                textArea.append(list[i] + '\n');                                        tempLeaf = new DefaultMutableTreeNode(NotKnown);                                        tempLeaf.setAllowsChildren(false);                                        p.add(tempLeaf);                                }                                else if(NotKnown.isDirectory())                                {                                textArea.append(list[i] + '\n');                                    tempDir = new DefaultMutableTreeNode(NotKnown);                                        tempDir.setAllowsChildren(true);                                        p.add(tempDir);                                 }                         }            }        catch(Exception e)                {                        System.out.println("Error: " + e);                 }        }

解决方案 »

  1.   

    TO:javaGirlOrBoy(javaGirl),Thank you very much....
    请问:
        1、取文件的路径用什么函数或方法?
        2、list是否将目录下所有文件都放进了list数组中?
        3、都需用哪些java包呀??
    忘告之,Thanks again.
      

  2.   

    其他的我也忘了,我给你的是别人写的,你只能作一下参考,里面有不对的地方,最好你多调试,调试,再看看java的文档 
    path.getLastPathComponent();
      

  3.   

    String dirname = "/java";
    File f1 = new File(dirname);
    if (f1.isDirectory()) {
    out.println("Directory of " + dirname);
    String s[] = f1.list();
    for (int i=0; i < s.length; i++) {
    File f = new File(dirname + "/" + s[i]);
    if (f.isDirectory()) {
    out.println(s[i] + " is a directory");
    } else {
    out.println(s[i] + " is a file");
    }
    }
    } else {
    out.println(dirname + " is not a directory");
    }
    }