如何知道文件之前是否被处理过
我如何确定文件之前是否已被处理过?有一个远程存储位置,它是我的应用程序的文件源。我的程序从该位置获取文件并按计划的方式处理它们。如何确定下次只获取未处理的文件?我正在考虑使用文件属性。存档和修改日期可以是一个解决方案。但我了解到有两位文件属性没有被使用。如何在 Java 中使用这些字段?顺便说一句,我不想使用数据库。
How can I be sure if a file was processed before? There is a remote storage location which is a file source for my application. My program gets files from this location and processes them in a scheduled way. How can I be sure that the next time I fetch only non-processed files? I'm thinking about using file attributes. The archive and modified date can be a solution. But I learned that two bits of file attributes are not used. How can I use these fields in Java? By the way I don't want to use a database.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一种常见的策略是使用某种形式的哈希函数来创建校验和。记录文件的校验和,并将校验和标识的已处理文件列表与相关文件进行比较。如果有问题的文件的校验和在列表中,则您已经处理了它。
保护已处理文件校验和的列表。如果你丢失了它,或者它被损坏了,这可能是漫长而糟糕的一天。
为了防止不必要的网络流量,您可以考虑在远程存储库上准备“检查”文件,其中包含与潜在输入文件相对应的校验和。
编辑:
根据进一步评论,有可能直接与文件系统属性交互。 提议的 Java 1.7 规范引入文件系统特定的属性视图来直接与这些属性交互。您感兴趣的视图是“DosFileAttributeView”。
基本用法可能与此类似(“输入”是基于 java“路径”的文件;添加必要的异常处理):
A common strategy is to use some form of hash function to create a checksum. Record the checksum of the file, and compare the list of processed files identified by checksum against the file in question. If the checksum of the file in question is in the list, you have already processed it.
Protect your list of processed file checksums. If you lose it, or it becomes corrupted, it might be a long, bad day.
To prevent unnecessary network traffic, you might consider preparing 'check' files on the remote repository that contain a checksum that corresponds to a potential input file.
EDIT:
Upon further comment, it is potentially possible to directly interact with file system attributes. The proposed Java 1.7 spec introduces file-system specific attribute views to directly interact with these attributes. The view you would be interested in is 'DosFileAttributeView'.
Basic use might be something similar to this ('input' is a file based on a java 'Path'; add necessary exception handling):
您可以重命名该文件(例如“filename.archive”)吗?或进入“存档”子目录?
Can you rename the file (e.g. "filename.archive")? or into an "archive" subdirectory?