⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fileinfo.java

📁 java实验报告书:其中包括实验代码以及说明等
💻 JAVA
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -