且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

下载文件夹的一般路径

更新时间:2023-01-10 22:41:11

查看这个问题
使用...

  String home = System.getProperty(user.home); 
文件文件=新文件(home +/ Downloads /+ fileName +.txt);


I have a DownloadTask class in java that takes a filename and URL, downloads that file and saves it to the downloads folder.

To save it to my downloads folder, I have the line

File file = new File("/users/myName/Downloads" + fileName + ".txt");

What can I replace this path with so that anyone can run the program and the file will be saved to their downloads folder?

Check out this question. Use...

String home = System.getProperty("user.home");
File file = new File(home+"/Downloads/" + fileName + ".txt");