Get the metadata of a file

后端 未结 5 2063
难免孤独
难免孤独 2020-11-27 20:11

It is possible to know the metadata of a file in java? and if it is, How to get the metadata of a file in java?

5条回答
  •  情书的邮戳
    2020-11-27 20:48

    I think is easy to use this folowing project to get informations from any files.

    import java.io.File;
    
    public class FileInfo{
        public static void main (String []args){
            File f = new File("file100.txt");
            if(f.exists()){
                System.out.println("Name: "+ f.getName());
                System.out.println("Path: "+ f.getAbsolutePath());
                System.out.println("Size: "+ f.length());
                System.out.println("Writeable: "+ f.canWrite());
                System.out.println("Readable: "+ f.canRead());
            }else{
                System.out.println("The File does not exist");
            }
        }
    }
    

提交回复
热议问题