?? chap8-1.txt
字號:
// 程序8-1
import java.io.*;
public class showAttribute {
void showAttributes(String fileName){ // 顯示文件屬性
File f=new File(fileName);
if(f.exists( )){ // 測試文件是否存在
System.out.println("Attributes of "+fileName);
System.out.println("Exist: "+f.exists( )); // 測試文件是否存在
System.out.println("Can read: "+f.canRead( )); // 測試文件是否可讀
System.out.println("Can write: "+f.canWrite( )); // 測試文件是否可寫
System.out.println("Is file: "+f.isFile( )); // 測試是否是文件
System.out.println("Is director: "+f.isDirectory( )); // 測試是否是目錄
System.out.println("Is absolute path: "+f.isAbsolute( )); //測試是否為絕對路徑
}else
System.out.println(fileName+" does not exist!");
}
public static void main(String args[ ]){
if(args.length!=1){
System.out.println("Usage: java fileTest <FileName> ");
System.exit(1);
}
showAttribute obj=new showAttribute ( ); // 生成一個fileTest類對象
obj.showAttributes(args[0]); // 顯示文件屬性
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -