0
0

More than 1 year has passed since last update.

Files.move

Posted at

test.txtをtest dirに移動するプログラム
移動先は...testではなく...test\test.txtを指定する

public class SampleProject {
    public static void main(String[] args) throws Exception{
        Path p1 = Paths.get("c:\\dirtest");
        File f = p1.toFile();
        method2(f);
        Path p2 = Paths.get("c:\\dirtest\\test.txt");
        Path p3 = Paths.get("c:\\dirtest\\test\\test.txt");
        Files.move(p2,p3);
        method2(f);
    }
    static void method2(File pf) {
        System.out.println("----------------");
        method(pf,"",null);
    }
    static void method(File pf, String indent, FileFilter ff) {
        class SampleClass {
            File[]  method() {
                if(ff == null) return pf.listFiles();
                else  return pf.listFiles(ff);
            }
        }
        File[] fs = new SampleClass().method();
        for(File f:fs) {
            System.out.print(indent + f.getName());
            if(f.isDirectory())  System.out.println("   is directory.");
            else  System.out.println("    is file");
            if(f.isDirectory())  method(f, indent + " ",ff);
        }
    }
}
----------------
sample.ser    is file
showa.txt    is file
test   is directory.
test.java    is file
test.txt    is file
testfile.txt    is file
testmakefile.txt    is file
testwritefile.txt    is file
----------------
sample.ser    is file
showa.txt    is file
test   is directory.
 test.txt    is file
test.java    is file
testfile.txt    is file
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