如题~!
File[] files = File.listRoots();
用这个可以得到系统盘符:如:c、d盘等
javax.swing.filechooser.FileSystemView; 这个类也看了,好像还是不可以哦。
如何得到呀 大家帮忙看下哦~!!谢谢啦就像这个样子的系统目录,说白了就是按Windows键+E建 出来的左边的那个目录。- Desktop
  + My Documents
  - My Computer(展开中)
    + WinXp(C:)
    + Programs(D:)
    + Backup(E:)
    + DVD-RAM Drive(F:)
    + Control panel
    + Shared Documents
    + Roger's Documents
  + My Network Places
  + Recycle Bin

解决方案 »

  1.   

    我给你帖些以前写的代码,修改一下就可以了:                request.setCharacterEncoding("gb2312");
    String strDir = request.getParameter("l");
    if (strDir != null && !strDir.equals("")) {
    //strDir = new String(strDir.getBytes("ISO-8859-1"), "GB2312").replace('/', '\\');
    strDir = new String(strDir.getBytes("ISO-8859-1"), "GB2312");
    }else if (strDir == null || strDir.length() < 1) {
    strDir = request.getRealPath("/");
    }

    StringBuffer sb = new StringBuffer("");
    StringBuffer sbFile = new StringBuffer("");
    try {
    File objFile = new File(strDir);
    File list[] = objFile.listFiles();
          if (objFile.getAbsolutePath().length() > 3) {
          sb.append("<tr>"+getDrivers()+"</tr>");
    }
    } catch (Exception e) {
    }
      

  2.   


     public static void main(String[] args) {
      String strPath = "e:\\treetest\\";
        try{
      
      File   dir   =   new   File("e:/treetest/newdata/");
      dir.createNewFile();
      File   file   =   new   File(dir,"myfile.txt");
      file.createNewFile();
     
      }catch(Exception ex){
      
      }
          try {
       getDir(strPath);
      } catch (Exception e) {
       e.printStackTrace();
      }
     } static void getDir(String strPath) throws Exception {  
     
      try {
       File f = new File(strPath);
       if (f.isDirectory()) {
        File[] fList = f.listFiles();
        for (int j = 0; j < fList.length; j++) {
         if (fList[j].isDirectory()) {
             System.out.println("Directory is: "+fList[j].getPath());
          getDir(fList[j].getPath());
          //getDir(fList[j].getName());
              
         }
        }
        for (int j = 0; j < fList.length; j++) {
         if (fList[j].isFile()) {
          String name=fList[j].getPath().toString();
          //System.out.println("filename  is: "+name);
         }
        }
       }
      } catch (Exception e) {
       System.out.println("Error: " + e);
      }
     }
      

  3.   

    我知道这样做是很对的,但是你知道我要的目录树,这个String strPath = "???";
    请问???应该是什么,Desktop ?不是,我试过了,这样不行,那么应该是什么呢,我不知道了。
      

  4.   

    import java.awt.BorderLayout;
    import java.io.File;import javax.swing.JFrame;
    import javax.swing.JScrollPane;
    import javax.swing.JTree;
    import javax.swing.event.TreeExpansionEvent;
    import javax.swing.event.TreeWillExpandListener;
    import javax.swing.filechooser.FileSystemView;
    import javax.swing.tree.DefaultMutableTreeNode;
    import javax.swing.tree.DefaultTreeModel;
    import javax.swing.tree.ExpandVetoException;
    import javax.swing.tree.TreePath;public class T
    {
    public static void main(String[] args)
    {
    FileSystemView fsv = FileSystemView.getFileSystemView();
    DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(null);

    for (File f : fsv.getRoots()) {
    FileTreeNode node = new FileTreeNode(f);
    rootNode.add(node);
    }
    DefaultTreeModel model = new DefaultTreeModel(rootNode);

    JTree tree = new JTree(model);
    tree.setRootVisible(false);
    tree.setShowsRootHandles(true);

    tree.addTreeWillExpandListener(new TreeWillExpandListener() {
    public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException
    {
    } public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException
    {
    TreePath path = event.getPath();
    if (path.getLastPathComponent() instanceof FileTreeNode) {
    FileTreeNode node = (FileTreeNode) path.getLastPathComponent();
    if (!node.hasListChildren()) {
    JTree tree = (JTree) event.getSource();
    node.listChildren((DefaultTreeModel) tree.getModel());
    }
    }
    }
    });

    JFrame f = new JFrame();
    f.getContentPane().add(new JScrollPane(tree), BorderLayout.CENTER);
    f.pack();
    f.setLocationRelativeTo(null);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
    }
    }class FileTreeNode extends DefaultMutableTreeNode
    {
    private boolean flag = false; public FileTreeNode(File dir)
    {
    super(dir);
    }

    public void listChildren(DefaultTreeModel model)
    {
    flag = true;
    File dir = (File) getUserObject();
    FileSystemView fsv = FileSystemView.getFileSystemView();
    File[] children = fsv.getFiles(dir, true);
    for (File child : children) {
    model.insertNodeInto(new FileTreeNode(child), this, getChildCount());
    }
    } public boolean hasListChildren()
    {
    return flag ;
    } @Override
    public String toString()
    {
    File dir = (File) getUserObject();
    FileSystemView fsv = FileSystemView.getFileSystemView();

    return dir == null ? "" : fsv.getSystemDisplayName(dir);
    }

    @Override
    public boolean isLeaf()
    {
    File dir = (File) getUserObject();
    FileSystemView fsv = FileSystemView.getFileSystemView();

    if (fsv.isFloppyDrive(dir)) {
    return false;
    }
    else {
    return dir.isFile();
    }
    }
    }
      

  5.   

     File f = new File(strPath);
       if (f.isDirectory()) {
        File[] fList = f.listFiles();
        for (int j = 0; j < fList.length; j++) {
         if (fList[j].isDirectory()) {
             System.out.println("Directory is: "+fList[j].getPath());
          getDir(fList[j].getPath());
          //getDir(fList[j].getName());