⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fileinfo.java

📁 JAVA学习源代码,大家可以好好参考,请多提宝贵意见
💻 JAVA
字号:
//FileInfo.java
import java.io.*; 
import java.util.*; 
public class FileInfo { 
    public static void main(String[] args) { 
        //若文件行没有输入文件名或路径名,则退出
        if(args.length==0){
            System.out.println("\nYou shoud input a file or directory name when executing!");
            return;
        }
        for (int i = 0; i < args.length; i++) { 
            //对每一个运行参数均创建一个File对象,并显示其信息
            File f = new File(args[i]);
            if (f.exists()) { 
                System.out.println("getName: " + f.getName());
                System.out.println("getPath: " + f.getPath());
                System.out.println("getAbsolutePath: " + f.getAbsolutePath()); 
                System.out.println("getParent: " + f.getParent()); 
                if (f.canWrite()) { 
                    System.out.println(f.getName() + " is writable."); 
                }
                if (f.canRead())  {
                    System.out.println(f.getName() + " is readable."); 
                }
                if (f.isFile()) { 
                    System.out.println(f.getName() + " is a file.");
                } 
                else if (f.isDirectory()) {
                    System.out.println(f.getName() + " is a directory."); 
                } else {
                    System.out.println("What is this?"); 
                }
                if (f.isAbsolute()) { 
                    System.out.println(f.getAbsolutePath()+ " is an absolute path.");
                }
                else {
                    System.out.println(f.getName() + " is not an absolute path."); 
                }
                System.out.println("Last Modified :" + new Date(f.lastModified())); 
                System.out.println(f.getName() + " is " + f.length() + " bytes."); 
            } 
            else {
                System.out.println("\nThe file or directory " + args[i] + "does not exist!\n");
           }
       }
   }
} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -