LoginSignup
0
0

More than 1 year has passed since last update.

Files class

Posted at
public class Outer {
    public static void main(String[] args) throws Exception{
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        System.out.println(str);
        Path p = Paths.get("c:\\dirtest\\" + str);
        File f = p.getParent().toFile();
        System.out.println(f);
        method(f);
        if(!Files.exists(p)) {
            Files.createFile(p);
        }
        method(f);
        System.out.println(Files.getLastModifiedTime(p));
//        System.out.println(Files.getPosixFilePermissions(p));
        System.out.println("delete ? y/n");
        str = sc.nextLine();
        if(str.equals("y")) {
            Files.delete(p);
        }
        method(f);
    }
    static void method(File pf) {
        System.out.println("-----------------------------");
        File[] fs = pf.listFiles();
        for(File f:fs) {
            System.out.print(f.getName());
            if(f.isDirectory())  System.out.println("   is directory.");
            else  System.out.println("    is file");
        }
    }
}
ppp.txt
ppp.txt
c:\dirtest
-----------------------------
cook.jpg    is file
cookcpy.jpg    is file
iii    is file
sample.ser    is file
showa.txt    is file
test.txt    is file
test2dir   is directory.
test3dir   is directory.
testdir   is directory.
testmakefile.txt    is file
testwritefile.txt    is file
-----------------------------
cook.jpg    is file
cookcpy.jpg    is file
iii    is file
ppp.txt    is file
sample.ser    is file
showa.txt    is file
test.txt    is file
test2dir   is directory.
test3dir   is directory.
testdir   is directory.
testmakefile.txt    is file
testwritefile.txt    is file
2023-02-06T06:33:41.611141Z
delete ? y/n
y
-----------------------------
cook.jpg    is file
cookcpy.jpg    is file
iii    is file
sample.ser    is file
showa.txt    is file
test.txt    is file
test2dir   is directory.
test3dir   is directory.
testdir   is directory.
testmakefile.txt    is file
testwritefile.txt    is file
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0