Java 使用exe4j文件创建setup.exe后,写入过程不起作用
我想创建日志文件并用java向该文件写入一些文本。我完成了该任务。当运行jar文件时,该代码运行良好。但在使用exe4j创建setup.exe后,文件写入过程不起作用。有人知道怎么做吗 这是我获取位于目录中的jar文件路径的方式Java 使用exe4j文件创建setup.exe后,写入过程不起作用,java,jar,file-writing,exe4j,Java,Jar,File Writing,Exe4j,我想创建日志文件并用java向该文件写入一些文本。我完成了该任务。当运行jar文件时,该代码运行良好。但在使用exe4j创建setup.exe后,文件写入过程不起作用。有人知道怎么做吗 这是我获取位于目录中的jar文件路径的方式 File f = null; public String baseUrl() { try { if (f == null) { f = new File(Register.class.getPr
File f = null;
public String baseUrl() {
try {
if (f == null) {
f = new File(Register.class.getProtectionDomain().getCodeSource().getLocation().toURI().getRawPath());
}
String path = f.getParent();
return path;
} catch (URISyntaxException ex) {
System.out.println(ex);
}
return "";
}
这是我的日志文件创建过程
try {
src.Log lg = new src.Log();
lg.setAction(action);
lg.setUserName(userName);
lg.setDescription(description);
lg.setTime(date);
lg.setSyncPath(syncPath);
lg.setMethod(method);
String url = baseUrl();
System.out.println(baseUrl());
String directoryName = url + "/ResFile";
File directory = new File(directoryName);
if (!directory.exists()) {
directory.mkdir();
}
File log = new File(directoryName + "/log.txt");
if (log.exists() == false) {
log.createNewFile();
}
try (PrintWriter out = new PrintWriter(new FileWriter(log, true))) {
out.append(lg.toString());
}
} catch (Exception ex) {
System.out.println(ex);
}
如果使用“JAR in EXE”模式,日志文件将位于临时目录中,因为在运行时,JAR文件就是在临时目录中提取的
要获取可执行文件所在的目录,可以使用
System.getProperty("install4j.exeDir")
如果使用“JAR in EXE”模式,日志文件将位于临时目录中,因为在运行时,JAR文件就是在临时目录中提取的
要获取可执行文件所在的目录,可以使用
System.getProperty("install4j.exeDir")
您好,我现在使用System.getProperty(“user.home”)+“\\AppData”在AppData文件夹中创建文件。您好,我现在使用System.getProperty(“user.home”)+“\\AppData”在AppData文件夹中创建文件。