Java访问权限:https://www.cnblogs.com/starhu/p/5143983.html

Class:public&default

变量&方法:public&protected&default&private

StringBuffer 使用: https://blog.csdn.net/qq_40817827/article/details/89313998

Map用法:https://blog.csdn.net/qq_29373285/article/details/81487594

Java泛型:https://www.cnblogs.com/coprince/p/8603492.html

Java命令行参数(用IDEA):https://blog.csdn.net/qq_34453300/article/details/86769834

Java文件目录相关:

  获取当前程序文件目录:https://blog.csdn.net/AsuKA_F/article/details/94488884

  获得文件信息(大小,修改时间):https://blog.csdn.net/qq_42446456/article/details/88357840

  关于File.seperator : https://www.cnblogs.com/xlizi/p/9303217.html

  列出Directory的文件信息,并递归下一层:https://blog.csdn.net/ikv1989/article/details/79743209

  关于打开目录查看文件信息的代码(递归目录树):

Usage:

java DirListing [-R] [-verbose] [directory]
import java.text.SimpleDateFormat;
import java.util.*;
import java.io.*;
class WrongFormatException extends Exception{
    public String toString(){
        return "Wrong Input Format";
    }
}
public class DirListing {
    static void printFile(File s,int type,int dep){
        for(int i=0;i<dep;++i){
            System.out.printf(" ");
        }
        if(s.isDirectory()){
            System.out.println(s);
            File[] result=s.listFiles();
            if(result!=null){
                for(int x=0;x<result.length;++x){
                    printFile(result[x],type,dep+2);
                }
            }
        }else{
            System.out.print(s);
            if(type==1){
                System.out.printf(" "+s.length()+"KB ");
                Date date=new Date(s.lastModified());
                SimpleDateFormat sd=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
                System.out.printf(sd.format(date));
            }
            System.out.println("");
        }
    }
    public static void main(String[] args) throws WrongFormatException{
        int type=0;
        if(!args[0].equals("[-R]")) throw new WrongFormatException();

        if(args[1].equals("[-verbose]")) type=1;
        else if(args[1].equals("[non-verbose]")) type=0;
        else {
            throw new WrongFormatException();
        }
        File f0=new File("");
        File f1=new File(f0.getAbsolutePath());
        if (args.length == 3) {
            f1=new File(args[3]);
        }

        if(f1.isDirectory()&&f1.exists()){
            printFile(f1,type,0);
        }else throw new WrongFormatException();
    }
}
View Code

相关文章:

  • 2021-11-28
  • 2022-02-22
  • 2022-02-24
  • 2022-01-21
  • 2021-09-02
  • 2021-12-08
  • 2021-07-31
猜你喜欢
  • 2022-12-23
  • 2021-10-29
  • 2021-07-26
  • 2021-07-29
  • 2022-01-12
  • 2022-02-22
  • 2022-12-23
相关资源
相似解决方案