fileinfo.java

来自「java的书上例子」· Java 代码 · 共 40 行

JAVA
40
字号
import java.io.*;
class fileInfo
{
	File fileToCheck;

	public static void main(String args[]) throws IOException
	{
		if (args.length>0)
		{
			for (int i=0;i<args.length;i++)
			{ 
				File fileToCheck = new File(args[i]);
				info(fileToCheck);
			}
		} 
		else
		{
			System.out.println("No file given."); 
		}
	}

	public static void info (File f) throws IOException 
	{
		System.out.println("Name: "+f.getName());
		System.out.println("Path: "+f.getAbsolutePath());
		if (f.exists())
		{
			System.out.println("File exists."); 
			System.out.print((f.canRead() ?" and is Readable":""));
			System.out.print((f.canWrite()?" and is Writeable":""));
			System.out.println("."); 
			System.out.println("File is " + f.length() + " bytes."); 
		}
		else 
		{
			System.out.println("File does not exist.");
		}
	}
}

⌨️ 快捷键说明

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