java _io_ File class file operations - file exists

File f = new File ( "C: / Users / 10853 / eclipse-workspace / hell / linux learning route .png");

File object methods of operation:

        f2.exists();   //文件是否存在
        f2.isDirectory();  //文件是否是目录
        f2.isFile();    //是否是文件
        new Date(f2.lastModified());//文件最后修改日期
        f2.length(); //文件大小
        f2.getName(); //文件名
        f2.getPath();   //文件的目录路径
        f2.getProperty("user.dir") //eclipse项目所在路径
        f2.getAbsolutePath() //文件的绝对路径
        f2.getParent() //返回文件父目录
        f2.createNewFile() //创建新txt文件
        f2.delete() //删除文件
        f.renameTo(new File("D:\\java_work\\jaj.txt"))  //ja被改名为jaj

Analyzing file status:
1, first exists () determines whether there
2, isFile () and the isDirectory () is a file or folder is determined

Create a txt file:
f = new new File ( "D: //d//d1//aa.txt"); // create a file you need to add a .txt file in the path inside
boolean Flag = f.createNewFile ();
System. out.println (flag); // determine whether to create a success

Guess you like

Origin blog.51cto.com/14437184/2422433