如题: 我想print一串字符保存成txt文件,放到到桌面上,问高手:如何取当前桌面路径? up有分。
解决方案 »
- 我学到JDBC了,很困惑,前辈指点一下我吧
- 菜鸟问题
- 请教 什么情况下BufferedReader流的readLine()方法返回null值?
- JInternalFrame出不来,帮帮忙看一下,谢谢
- JAVA能拦包吗??就是类似于自动外挂挂机的那种.急急!!!!!!!
- Encoding 的问题?
- 请教各位高手JSpinner输入格式控制问题。急!谢谢!!
- CSDN 社区用户准则页面用firefox打开乱码
- 请问参加SCJP考试要注意一些什么?
- Error:Main method not public.
- 请教简单问题:JCreator、Ant、IntelliJ IDEA分别是哪些公司开发的?
- 奇怪,为什么 string 用 byte <<= 1 后,再 byte >>= 1,再 new String(b),得到的字符串为什么不是原来的 string ,怎么样才能得回原来
File root = fsv.getHomeDirectory().getPath();或者:
File root = fsv.getRoots()[0];//-----------关于FileSystemView的用处可以参阅sun的jdk文档
File root = fsv.getHomeDirectory().getPath();是错误的,更正如下:
File root = fsv.getHomeDirectory();
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[]全部打印出来看看,按文档说是桌面的
File root = fsv.getHomeDirectory();
System.out.println(root.getPath());
FileOutputStream fos = new FileOutputStream(root.getPath()+"\\1.txt");
fos.write(97);
fos.close();
我打出来是:path=C:\Documents and Settings\chilexun
System.getProperty("user.home"); 得到 %Profile% , 也就是用户对应的目录,
然后你看是英文系统就用 %Profile%/desktop , 中文就用 %Profile%/桌面,这还要用到
System.getProperty("user.language") 判断语言 , zh , zh_CN 对中文。