Java webapp 无法将图像写入 webapp 创建的文件夹

Java webapp can't write image to folder created by webapp

我有一个 Web 应用程序,我有几个操作。其中一项操作会在上下文之外将一些图像写入文件夹,比如:

/home/user/images/subfolder1/image.jpg

现在,另一个操作将该图像复制到位于图像内的另一个文件夹,但具有不同的扩展名,比如说:

/home/user/images/subfolder2/subsubfolder2-1/image.png

现在,第一张图片是从表单中获取的,第二张图片是从第一张图片保存的路径中获取的,两张图片的写入方法相同:

InputStream in = new FileInputStream(origen);
OutputStream out = new FileOutputStream(destination.getAbsolutePath());

while ((len = in.read(buf)) > 0) {
   out.write(buf, 0, len);
}  

Web 应用程序创建每个文件夹,包括 "subfolder2/subsubfolder2-1/" 如果它们不存在则使用 mkdirs()。

这在我的测试环境中工作得很好 运行 ubuntu 14.04 和 apache tomcat 6.0.43,但是,在生产环境中,是 centos 6(或 6.5),相同的 apache tomcat 版本,创建了图像,但没有向其中写入数据,我的意思是,创建了一个 image.png 文件,但其大小为 0。所有文件夹都有正确的权限,drwxrwxrwx , 但 image.png 由于某种原因,缺少它们,只有 rw.

这可能是什么原因造成的?

出于某种未知原因,我将文件写入方式更改为:

        InputStream in = new FileInputStream(origen);
        OutputStream out = new FileOutputStream(destination.getAbsolutePath());

        int byteRead = 0;
           byte[] buffer = new byte[8192];
           while ((byteRead = in.read(buffer, 0, 8192)) != -1){
               out.write(buffer, 0, byteRead);
            }

而且运行正常,不知道是什么原因。