Java 服务无法写入文本文件
Java service cant write to text file
当我 运行 在 eclipse 中使用以下代码时,它按预期工作,但是当我安装它并且 运行 作为服务时,仅输出 PNG 文件。
int maxBound = 0;
try
{
File outputfile = new File("image.png");
ImageIO.write(drawImage(), "png", outputfile);
File boundsfile = new File("bounds.txt");
FileWriter fw = new FileWriter(boundsfile);
BufferedWriter bw = new BufferedWriter(fw);
bw.write(maxBound+" ");
bw.close();
}
catch (IOException e)
{
log.info(e.getMessage());
}
正在写入日志文件(同一 class 中的其他地方),但是没有错误消息。不确定我在这里遗漏了什么。
我把它换成了这个,现在可以用了。
FileWriter fw = new FileWriter("bounds.txt");
fw.write(maxBound+" ");
fw.close();
不确定问题出在哪里,但这有效。
当我 运行 在 eclipse 中使用以下代码时,它按预期工作,但是当我安装它并且 运行 作为服务时,仅输出 PNG 文件。
int maxBound = 0;
try
{
File outputfile = new File("image.png");
ImageIO.write(drawImage(), "png", outputfile);
File boundsfile = new File("bounds.txt");
FileWriter fw = new FileWriter(boundsfile);
BufferedWriter bw = new BufferedWriter(fw);
bw.write(maxBound+" ");
bw.close();
}
catch (IOException e)
{
log.info(e.getMessage());
}
正在写入日志文件(同一 class 中的其他地方),但是没有错误消息。不确定我在这里遗漏了什么。
我把它换成了这个,现在可以用了。
FileWriter fw = new FileWriter("bounds.txt");
fw.write(maxBound+" ");
fw.close();
不确定问题出在哪里,但这有效。