简体   繁体   English

如何在Java中获取文件和文件夹信息?

[英]how to get the file and folder information in java?

I'm doing a project that has a module as "File or folder information". 我正在做一个项目,该项目的模块为“文件或文件夹信息”。 It means, I need all open files and open directory details. 这意味着,我需要所有打开的文件和打开的目录详细信息。

Eg: 例如:

If one file "aa.txt" was open by user, and the file is in "bb directory"; 如果用户打开了一个文件“ aa.txt”,并且该文件位于“ bb目录”中; the output should be like 输出应该像

 aa.txt that file be in open bb dir be in open 

and also, if you change that file, the message appear by that module as aa.txt that file has been modified by this user. 并且,如果您更改该文件,则该模块将以aa.txt that file has been modified by this user.该文件的消息aa.txt that file has been modified by this user.

You won't be able to do that in pure java, you'll need to use a custom library (depending on the OS) as file/user/permissions information is hidden form Java to make it portable. 您将无法在纯Java中做到这一点,您将需要使用自定义库(取决于OS),因为文件/用户/权限信息被Java隐藏以使其可移植。 You can only check if you can read or write to a file using standard java (you have few more methods as isDirectory, but not much more). 您只能检查是否可以使用标准Java读取或写入文件(与isDirectory一样,您还有其他几种方法,但没有更多方法)。

Please have a look at Java's java.io.File API. 请查看Java的java.io.File API。 You will get most of the things there. 您将在那里得到大部分东西。 For checking if the file has been modified, you can use lastModified() method. 要检查文件是否已被修改,可以使用lastModified()方法。

JDK 7 is giving a new The WatchService API and File Change Notification API . JDK 7提供了新The WatchService API and File Change Notification API You can read about it here . 你可以在这里阅读。

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

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