Good day! I am completely new to java, I have the following question, is the receipt of folder and drive attributes different from files? I mean the name, the size of the folder or drive, the date of creation, the date of the change.

Here is an example of getting an attribute from a file:

File file = new File(pach); if (file.isFile()) { //заносим данные в структуру FI FI.NameFile = file.getName(); FI.TypeFile = "file"; FI.SizeFile = (int) file.length(); FI.DateCreate = "???"; FI.DateEdit = new Date(file.lastModified()); } 

How to get in this way the attributes of folders and drives?

    1 answer 1

    I just tried, the size of the folder with a bunch of files turned out to be 4kb, so to find the size of the entire folder you need to recursively go through all the subfolders and add file sizes using the file.length () method. Unfortunately, there is no standard solution have to use third-party tools Everything else seems to be the same

    • Thanks for the answer ... I will think in this direction. - IntegralAL
    • I will only add that recursive file system crawling is a slow operation; do not try to execute it without explicitly prompting the user. - VladD
    • And, by Google it turned out that the date of file creation can be found with the help of nio - Sevak Avetisyan
    • I also already found out). - IntegralAL
    • folder size can also be determined through the module nio - IntegralAL