?? filedemo.java
字號:
//運用File類的常用方法,獲取有關文件屬性的信息。
import java.io.File;
class FileDemo
{
static void OutOper(String s)
{
System.out.println(s);
}
public static void main(String args[]) {
File f1 = new File("/java/COPYRIGHT");
//調用File類的toString方法輸出對象f1的路徑
System.out.println(f1);
//獲取該文件的各個屬性和信息
OutOper("File Name: " + f1.getName());
OutOper("Path: " + f1.getPath());
OutOper("Abs Path: " + f1.getAbsolutePath());
OutOper("Parent: " + f1.getParent());
OutOper(f1.exists() ? "exists" : "does not exist");
OutOper(f1.canWrite() ? "is writeable" : "is not writeable");
OutOper(f1.canRead() ? "is readable" : "is not readable");
OutOper("is " + (f1.isDirectory() ? "" : "not" + " a directory"));
OutOper(f1.isFile() ? "is normal file" : "might be a named pipe");
OutOper(f1.isAbsolute() ? "is absolute" : "is not absolute");
OutOper("File last modified: " + f1.lastModified());
OutOper("File size: " + f1.length() + " Bytes");
//將 f1對象改名為"newFile"
File f2 = new File("newFile");
OutOper("\n"+"****now rename the file " + f1 +" to " +f2 +"****");
f1.renameTo(f2);
OutOper("name"+f2.getName());
//檢查改名前的那個文件是否存在
OutOper(f1+"is exist?" +f1.exists());
//刪除改名后的文件
OutOper("\n"+"****delete"+f2+"****");
f2.delete();
OutOper(f2 + "exist?" + f2.exists());
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -