Java服务无法写入文本文件

Java服务无法写入文本文件,java,file,service,Java,File,Service,当我在eclipse中运行以下代码时,它会按预期工作,但是当我安装它并作为服务运行时,只输出PNG文件 int maxBound = 0; try { File outputfile = new File("image.png"); ImageIO.write(drawImage(), "png", outputfile); File boundsfile = new File("bounds.txt");

当我在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());
    }   
        FileWriter fw = new FileWriter("bounds.txt");
        fw.write(maxBound+" ");
        fw.close();

正在写入日志文件(同一类中的其他位置),但是没有错误消息。不确定我在这里遗漏了什么。

我把它换成了这个,现在可以用了

        FileWriter fw = new FileWriter("bounds.txt");
        fw.write(maxBound+" ");
        fw.close();

不确定问题出在哪里,但这是可行的。

试试这个:
FileWriter fw=newfilewriter(boundsfile.getAbsoluteFile())。。几天前,我遇到了一个问题,其中一个测试开始失败,因为它找不到文件(在那里),当我将构造函数从文件更改为绝对URL时,它开始工作。我最初尝试了这个,但没有运气。最后,我完全删除了BufferedWriter,它成功了。不确定到底是什么问题。谢谢你的帮助。
        FileWriter fw = new FileWriter("bounds.txt");
        fw.write(maxBound+" ");
        fw.close();