用于Java文件输出的桌面路径
我有一个程序,它将输出一个文本文件并保存在用户的计算机中,我想把它保存在桌面上,因为这是每个人都会有的路径 我目前正在Windows 8中编码,我应该使用哪个路径来保证它将保存到Windows 7上的桌面用于Java文件输出的桌面路径,java,desktop,Java,Desktop,我有一个程序,它将输出一个文本文件并保存在用户的计算机中,我想把它保存在桌面上,因为这是每个人都会有的路径 我目前正在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 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!");
我从来不会使用一个程序,悄悄地将文件保存到我的桌面上。您只需询问用户,将文件放在哪里。linux用户的桌面路径与桌面路径不同windows@Seelenvirtuose如何提示用户保存到哪里??再次阅读我的问题,我在那里添加了我的代码,我不知道如何使代码看起来整洁这里我如何才能将我的与你的合并???@user1977 mine
String content=(jLabel1.getText()+“\r\n”+N1.getText()+”\r\n“+L1.getText())
文件File=新文件(“C:/Users/Wil/Downloads/Dropbox/abc.txt”)代码>没关系,收到了谢谢!这对mac有用吗?
File desktop = new File(System.getProperty("user.home"), "Desktop");