我在读取 .xlsx 文件时遇到问题。每当我使用 WorkbookFactory.create(inputStream); 时,都会在 /tmp/poifiles 目录下创建一些具有随机名称的临时文件。该目录是为第一个用户使用 RW-RR- 权限创建的。因此,当同一台计算机上的另一个用户尝试访问这些文件时,他无法访问。
请以任何方式建议我
1) 如何在 /tmp 目录下创建这些临时文件,而不总是在 /tmp/poifiles 中(我使用的是 RHEL V5.0)
2) 以及如何配置 POI,例如更改位置它在哪里读取临时文件?
迫切需要帮助解决不同用户通过 POI 访问相同 .xlsx 文件的问题。
I am stuck with an issue with reading .xlsx file. Some temporary files with random name are created under /tmp/poifiles directory whenever I use WorkbookFactory.create(inputStream);. This directory is created with RW-R-R- permission for the first user. So another user on the same machine when tries to access these files, he CANNOT.
Please suggest me any way
1) How can I create these temp files under /tmp directory and not always in /tmp/poifiles (I am using RHEL V5.0)
2) and how can I configure POI such as to change the location from where it reads the temporary files??
Anymore help to solve my problem of different users accessing same .xlsx files through POI is badly needed.
发布评论
评论(2)
Yuppie...我找到了解决方案...
POI 使用以下方法创建临时文件。
现在我们可以看到它从属性“java.io.tmpdir”获取位置并在其中创建 poifiles 目录...
我通过设置此属性更改了 java.io.tmpdir 的位置(使用 System.setProperty("java .io.tmpdir”,“somepath”))到用户特定位置..瞧......现在每个用户都可以在他们始终可以访问的位置创建临时文件,并且不仅第一个用户获得创建只能访问的目录的权限对他...!!!
Yuppie...I got the solution....
POI uses the following method to create temp files.
Now here as we can see it gets the location from property "java.io.tmpdir" and creates poifiles directory inside that...
I changed the location of java.io.tmpdir by setting this property (using System.setProperty("java.io.tmpdir", "somepath"))to user specific location..and Voila....Every user now can create temp files at location always accessible to them and not only the first user gets the privilege to create directory accessible only to him ...!!!
如果您无法更改系统属性“java.io.tmpdir”,则可以通过以下方式更改 POI 以编程方式读取临时文件的位置。
这是由 Apache POI TempFile 和 DefaultTempFileCreationStrategy 帮助器类。
Here is how you can change the location from where POI reads the temporary files programmatically if you are not able to change system property "java.io.tmpdir"
This is driven by the Apache POI TempFile and DefaultTempFileCreationStrategy helper classes.