如题:  我想print一串字符保存成txt文件,放到到桌面上,问高手:如何取当前桌面路径?  up有分。

解决方案 »

  1.   

    import javax.swing.filechooser.FileSystemViewFileSystemView fsv = FileSystemView.getFileSystemView();
    File root = fsv.getHomeDirectory().getPath();或者:
    File root = fsv.getRoots()[0];//-----------关于FileSystemView的用处可以参阅sun的jdk文档
      

  2.   

    更正个笔误。
    File root = fsv.getHomeDirectory().getPath();是错误的,更正如下:
    File root = fsv.getHomeDirectory();
      

  3.   

    好的,还差一步,就是root.getPath() 后的路径 后面少一个   \桌面\  ,在桌面还是看不到啊。
      

  4.   

    对于98 系统,后面少一个 \desktop\ 呀。
      

  5.   

    public File[] getRoots()
    Returns all root partitions on this system. For example, on Windows, this would be the "Desktop" folder, while on DOS this would be the A: through Z: drives. 
    ---------------------------------
    以上是jdk的FileSystemView的getRoots()文档。我这里2000测试是通过的。desktop应该会有的阿,要不你把getRoots()方法返回的File[]全部打印出来看看,按文档说是桌面的
      

  6.   

    测试通过FileSystemView fsv = FileSystemView.getFileSystemView();
    File root = fsv.getHomeDirectory();
    System.out.println(root.getPath());

    FileOutputStream fos = new FileOutputStream(root.getPath()+"\\1.txt");
    fos.write(97);
    fos.close();
      

  7.   

    believefym(feng) 我的qq是 54265317  我们讨论一下吧,奇怪了。
    我打出来是:path=C:\Documents and Settings\chilexun
      

  8.   

    你是不是打印的root.getParent()了..
      

  9.   

    File.getRoots() 不是返回所有驱动器么?
    System.getProperty("user.home"); 得到  %Profile% , 也就是用户对应的目录,
    然后你看是英文系统就用 %Profile%/desktop , 中文就用 %Profile%/桌面,这还要用到 
    System.getProperty("user.language") 判断语言 , zh , zh_CN 对中文。