📄 checkfile2.java
字号:
import java.io.*;
public class CheckFile2
{
public static void main(String[] args)
throws java.io.IOException
{
String fileName = "C:\\jdk\\prices.dat";
String nextName = "backup.dat";
File inFile = new File(fileName);
File newName = new File(nextName);
if (inFile.exists())
{
System.out.println("The file " + fileName + " exists");
// check the type of file
if (inFile.isDirectory())
System.out.println(" This is a directory");
else if (inFile.isFile())
System.out.println(" This is a regular file");
// check if file is readable
if (inFile.canRead())
System.out.println(" The file can be read");
else
System.out.println(" The file is not readable");
// check if file is writable
if (inFile.canWrite())
System.out.println(" The file can be written to");
else
System.out.println(" The file is not writeable");
// report the file's length
System.out.println("The file length is " + inFile.length() + " bytes.");
// report the file's directory path
System.out.println("The pathname of this file's parent is " + inFile.getParent());
// rename the file
inFile.renameTo(newName);
System.out.println("The file has been renamed " + newName);
System.out.println("The full pathname for this file is " + newName.getAbsolutePath());
}
else
System.out.println("The file " + fileName + " does not exist.");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -