📄 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 + -