如何找到“我的文件” Java中的文件夹 [英] How to find "My Documents" folder in Java
本文介绍了如何找到“我的文件” Java中的文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我愿意在用户的我的文档文件夹中保存文件。
I'm willing to save a file in the user's "My Documents" folder.
我尝试获取这样的位置:
I tried getting the location like this :
System.getenv("USERPROFILE") + "\\My Documents\\"
然后,我意识到这不适用于将语言设置为其他语言的系统,例如法语。
Then, I realized this wouldn't work in a system where the language is set to another language, french for example.
是否有其他方式可以有效地获取我的文档文件夹?
Is there another way of getting the "My Documents" folder efficiently?
推荐答案
如果你不喜欢根据Swing你可以明显地使用这个技巧:
If you don't mind depending on Swing you can apparently use this trick:
import javax.swing.JFileChooser;
javax.swing.filechooser.FileSystemView;
public class GetMyDocuments {
public static void main(String args[]) {
JFileChooser fr = new JFileChooser();
FileSystemView fw = fr.getFileSystemView();
System.out.println(fw.getDefaultDirectory());
}
}
(来源: http://www.rgagnon.com/javadetails/java-0572.html )
这篇关于如何找到“我的文件” Java中的文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文