简体   繁体   English

在Java中压缩目录是否会影响使用相同文件的其他进程?

[英]Will zipping a directory in Java affect other processes using the same files?

I'm using the java.util.zip library and ZipOutputStream in order to create a zip file of a directory and all the files and directories under it. 我正在使用java.util.zip库和ZipOutputStream来创建目录的zip文件以及其下的所有文件和目录。 In my application, it is likely that another thread could be accessing these same files during the compression. 在我的应用程序中,很可能另一个线程可能在压缩期间访问这些相同的文件。 I'm not an expert on file compression (or thread-safety, for that matter) so my question is, will zipping a directory while something else is accessing those files affect either process? 我不是文件压缩(或线程安全,就此而言)的专家,所以我的问题是, 在其他人访问这些文件时会压缩目录会影响这两个进程吗?

Only if the processes have opened the files in such a way that prevents read access by other processes. 仅当进程以防止其他进程读取访问的方式打开文件时。 (This usually requires OS-specific flags to specify the permissions.) So it's certainly possible, but it's not the common case. (这通常需要特定于操作系统的标志来指定权限。)所以它当然是可能的,但这不是常见的情况。

Assuming that you're operating on Windows, and that your concurrent access is read-only, then I would expect the zipping process not to affect anything. 假设您在Windows上运行,并且您的并发访问是只读的,那么我希望压缩过程不会影响任何事情。

For a detailed approach to Java File Locking, see the JDC Tech Tips . 有关Java文件锁定的详细方法,请参阅JDC技术提示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM