文件输出 Java 的桌面路径
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21022598/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 06:01:55 来源:igfitidea点击:
Desktop path for file output Java
提问by user3177001
I have this program where it will output a text file and save it in the user's computer, I wanted to save it at desktop since that's the path everyone would have.
我有这个程序,它将输出一个文本文件并将其保存在用户的计算机中,我想将其保存在桌面上,因为这是每个人都会拥有的路径。
I'm currently coding in Windows 8, which path should I use to guarantee it'll save to desktop on Windows 7??
我目前正在 Windows 8 中编码,我应该使用哪个路径来保证它会在 Windows 7 上保存到桌面??
File file = new File("C:/Users/Wil/Downloads/Dropbox/abc.txt");
// if file doesnt exists, then create it
if (!file.exists()) {
file.createNewFile();
}
FileWriter fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
bw.write(content);
bw.close();
JOptionPane.showMessageDialog(null,"Receipt Saved!");
采纳答案by user1977351
File desktop = new File(System.getProperty("user.home"), "Desktop");