【发布时间】:2016-03-23 04:33:16
【问题描述】:
我有一个包含以下代码行的程序:
//String s = fileName;
File location = new File(s);
然后我有
//String contents = whatIWantToPrint;
OutputStream print = new FileOutputStream(location);
print.write(contents.getBytes());
print.close();
告诉程序将字符串内容打印到文件 s。但是,该文件出现在程序所在的文件夹中,而不是程序所在的目录中。例如,如果程序在个人桌面上,我希望它在他们的桌面上制作文件。
我在终端中使用以下行将程序制作为 jar 文件(mac):
jar -cvmf manifest.txt Generate.jar *.class
有人告诉我这样做:
String dir = System.getProperty("home.dir"+"/Desktop");
String filePath = dir + File.separator + ss + ".txt";
File location = new File(filePath);
但我不确定这是否会使程序在桌面上生成文件,并且它还会引发安全异常,因此无论如何它都不起作用
【问题讨论】:
标签: java jar properties system