4.18

文件操作

复制代码
import java.io.File;

public class UseFile {
    public static void main(String args[]){
        File f  = new File("file1.txt");
        System.out.println("the file is exists?   "+ f.exists());
        System.out.println("the file is write?   " + f.canWrite());
        System.out.println("the file is read ?   "+ f.canRead());
        System.out.println("the file is a file " +f.isFile());
        System.out.println("the file's path is ?    "+ f.getPath());
        System.out.println("the file's absolute path is "+ f.getAbsolutePath());
        System.out.println("the file's parent path is ?" + f.getParent());

        File newfile = new File("newfile.txt");

        f.renameTo(newfile);
        System.out.println(newfile.getName());
        System.out.println("if file is exists?" + f.exists());
        f.delete();
        newfile.delete();
        System.out.println("if file is exists?" + f.exists());

    }

}

posted on 2024-04-18 23:16  HA_wind  阅读(8)  评论(0编辑  收藏  举报

导航