fileinfo.java

来自「java实验报告书:其中包括实验代码以及说明等」· Java 代码 · 共 28 行

JAVA
28
字号
import java.io.*;
class FileInfo{
   public static void main(String[ ] args){
      System.out.println("Enter file name:");
			char c;
			StringBuffer buf=new StringBuffer();
			try{
						while((c=(char)System.in.read())!='\n')
							buf.append(c);//将输入的字符加到buf中,直到出现回车符
			}
			catch(java.io.IOException e){
				System.out.println("Enter:"+e.toString());
			}
			File file=new File(buf.toString().trim());//创建File类的file对象
			if(file.exists()){//如果文件当前目录存在
				System.out.println("File Name:"+file.getName());//显示文件名
				System.out.println("Path:"+file.getPath());//显示文件路径
				System.out.println("Abs.Path:"+file.getAbsolutePath());//显示文件的绝对路径
				System.out.println("Writable:"+file.canWrite());//显示文件是否可写
				System.out.println("Readable:"+file.canRead());//显示文件是否可读
				System.out.println("Length:"+(file.length())+"B");//显示文件的大小
			}
			else//如果文件在当前目录不存在
				System.out.println("Sorry,file not found.");//显示文件没有找到的提示信息
   }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?