testfile.java

来自「这是我自己照着书上敲的」· Java 代码 · 共 70 行

JAVA
70
字号
/*
 * Created on 2007-9-22
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
import java.io.*;
/**
 * @author Administrator
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class TestFile 
{
	public static void main(String args[])
	{
		System.out.println("Input the Directory or file path:");
		char in='a';
		StringBuffer input=new StringBuffer("");
		try
		{
			in=(char)System.in.read();
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		while(in!='\n'&&in!='\r')
		{
			try
			{
				input.append(in);
				in=(char)System.in.read();
			}
			catch(Exception e)
			{
				e.printStackTrace();
			}
		}
		File file=new File(input.toString());
		if(file.exists())
		{
			if(file.isFile())
			{
				System.out.println("File found!");
				System.out.println("File name:"+file.getName());
				System.out.println("Absolute Path:"+file.getAbsolutePath());
				System.out.println("Readable rights is:"+file.canRead());
				System.out.println("Writeable rights is:"+file.canWrite());
			}
			else
				if(file.isDirectory())
				{
					System.out.println("Directory found!");
					System.out.println("Absolute Path:"+file.getAbsolutePath());
					System.out.println("Directory listing:");
					String[] list;
					list=file.list();
					int i;
					for(i=0;i<list.length;i++)
						System.out.println(list[i]);					
				}
		}
				else
				{
					System.out.println("File not found!");
				}
	}

}

⌨️ 快捷键说明

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