- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在使用 Files.createFile() 的测试服务器上遇到了非常奇怪的行为。
代码如下:
Files.createFile(myPath);
... code adding that file to a zip file ...
在 myPath 中创建的文件有时不包含在 zip 内容中,大多数情况下不包含,不会抛出异常。我永远无法在运行 CentOS 版本 6.6(最终版)并具有 ext4 文件系统的测试服务器之外重现该问题。在 createFile 之后执行 Files.exists(myPath) 始终返回 true。
我尝试向文件中写入几个字符以检查是否有影响,但没有。
FileUtils.writeStringToFile(testLog.toFile(), "Test content");
如果我在中间添加一个短暂的 sleep ,该文件就会一致地包含在 zip 中。
持续工作:
Files.createFile(myPath);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
//interrupted
}
... code adding that file to a zip file ...
我对此的看法是,文件系统中发生了一些奇怪的异步行为,因为 Thread.sleep() 永远不会在这段代码中产生任何差异。
有人对 sleep 如何产生影响有明确的解释吗?
编辑:我这里的问题实际上不是关于压缩方法,而是关于 createFile 方法的异步行为,而它不应该这样做。
感谢您的帮助!
最佳答案
为什么不直接使用 zip 文件系统提供程序?
final Path zipPath = Paths.get("pathToZipFileHere");
final URI uri = URI.create("jar:" + zipPath.toUri());
final Path fileInZip;
// Open the zip as a filesystem
try (
final FileSystem fs = FileSystems.newFileSystem(uri,
Collections.emptyMap());
) {
fileInZip = fs.getPath("path/in/zip");
// work with fileInZip
}
关于java - Files.createFile() 可以有异步行为吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33787160/
我正在尝试使用 JNA 在 Windows 7 上调用 Win32 的 CreateFile 函数,目的是执行 this answer 的 Java 实现以检查文件是否正在被另一个进程使用。 我目前的
char tempFilename[256]; wchar_t filename[512]; fprintf(stdout, "Please enter file name/path: \n")
我正在尝试记录我使用 Windows-API 和 C 语言编写的服务所做的操作,因此我制作了一个日志文件系统。 问题是在每次调用 CreateFile 时,文件都会被覆盖,而不是仅仅打开它并在文件末尾
CreateFile()可以在两个不同的线程中同时打开一个文件吗 void new_function(void * what) { HANDLE h = CreateFile("c:\\tmp", G
知道为什么 createfile() 函数会返回 -1。 Handle = CreateFile(filename, &H80000000, 0, 0, 3, &H80, 0) 这运行了几次。我在想也
我想经常在文件中写入数据, 不知道是不是每次写的时候都调用 CreateFile() , 这种方式是否比我只调用一次的方式花费那么多,然后 多次使用 handle ? 最佳答案 如果要多次写入文件,最
我正在使用 CreateFile() 打开并读取文件。如果抛出异常,文件是否会被关闭,或者我是否需要捕获它并自己关闭文件。如果后者是真的,捕获并关闭文件的最佳方法是什么。谢谢! 最佳答案 文件不会关闭
HANDLE hFile = CreateFile(LPCTSTR("filename"), // name of the write
我正在尝试从 exe 文件所在的目录中读取文件。 data.txt 文件位于 VS Project 目录中,当我指定完整路径时,一切正常。 char curDirectory[MAX_PATH]; G
我正在使用 CreateFile打开设备。一切正常,直到设备名称太长。 在文档中说: In the ANSI version of this function, the name is limited
这个问题在这里已经有了答案: How to open COMXX files(serial port) (1 个回答) 关闭 7 年前。 我正尝试通过我的 USB 端口(名为 COM15)进行一些串
我正在窃取 plink 的源代码使其与统一兼容。 如果你不知道,unison 是一个文件同步工具,它运行一个“ssh”命令来连接到远程服务器,但 Windows 没有 ssh.exe;有 plink,
我正在使用 Delphi 2010,并正在寻找一种使用 CreateFile Windows API 函数追加数据而不是在指定文件中覆盖数据的方法? 我并不是在寻找一种可选的方法来做到这一点,例如 A
我正在尝试使用Golang 1.14中的windows.CreateFile()函数创建文件(有关引用,请参阅https://godoc.org/golang.org/x/sys/windows#Cr
所以我将这些东西从 C++ 移植到 C#。它的一部分看起来像这样: m_hParstat = CreateFile( _T("\\\\.\\LPTSTAT1"), GENERIC_READ
我在使用 Files.createFile() 的测试服务器上遇到了非常奇怪的行为。 代码如下: Files.createFile(myPath); ... code adding that file
程序在 Windows 计算机上创建一个文件来记录其进度。程序结束时,文件将关闭并保留在系统上。具有网络访问权限的用户希望远程打开文件以查看最近记录的条目。 该文件是使用fopen_s打开的,文档中没
我需要以原始模式打开读取磁盘,因此我为此目的使用了 CreateFile API 函数。 private static FileStream OpenDisk(string drive) {
我正在尝试利用 CreateFile 函数来访问目录信息。但是,我收到 win32 错误代码 5,这意味着访问被拒绝。请指教。 CreateFile(path, GENERIC_READ, FILE_
我拥有管理员权限,可以毫无问题地获得有效句柄并最终通过以下方式读取整个硬盘: IntPtr handle = CreateFile(@"\\.\PHYSICALDRIVE1", GENERIC_REA
我是一名优秀的程序员,十分优秀!