![](/img/trans.png)
[英]Log in using Java where server's authentication could be sso or web applcation container's basic
[英]Where could I save a log file in a server using web wervice JAVA (.war)?
我使用 JAVA 创建了一个 web 服务。 我想在服务器中创建一个日志文件以便稍后恢复它,但我的问题是由于客户端权限我无法保存该文件。 在我的本地服务器中,我可以将它保存在根路径中,但在我将使用它的 Devian 服务器中,这是不可能的。 我尝试更改路径,但问题仍然存在,因为我的本地路径与其他服务器不同。 这是我的代码:
BufferedWriter bw = null;
FileWriter fw = null;
try {
File file = new File(System.getProperty("user.dir")+File.separator+"zlm_"+thoy+".txt");
// Si el archivo no existe, se crea!
if (!file.exists()) {
file.createNewFile();
}
// flag true, indica adjuntar información al archivo.
fw = new FileWriter(file.getAbsoluteFile(), true);
bw = new BufferedWriter(fw);
bw.write(entrada+";"+porcentaje+";");
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
//Cierra instancias de FileWriter y BufferedWriter
if (bw != null)
bw.close();
if (fw != null)
fw.close();
} catch (IOException ex)
{
ex.printStackTrace();
}
}
有任何想法吗?
我建议将它放在 /var/log 或 /tmp 目录中。 如果您仍然没有这些目录的权限,您可以随时将其放在 war 文件的相对/工作目录中。
有关如何在此答案中的工作目录中创建文件的更多信息。
使日志文件的路径可配置,以便服务器管理员可以设置它。 向管理员询问测试它的路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.