filedemo11.java
来自「JAVA程序设计课程中各章节的程序实例。」· Java 代码 · 共 45 行
JAVA
45 行
/**
*This program illustrates the use of the File class to check
* whether the path given specifies a file or a directory
*If it's a directory,it prints th edirectory infornmation,otherwise,gives approriate messages
*2004.12.30. xhcprince
*/
import java.io.*;
class fileDemo11
{
public static void main(String args[]) throws IOException
{
File f1 = new File("c.doc"); //if it's a file,you have to add the suffix!
if(f1.exists() == true)
{
System.out.println("Existing");
if(f1.isDirectory() == true)
{
System.out.println("It's a directory");
String[] arr = f1.list();
int i;
for(i=0; i<arr.length; ++i)
{
System.out.println("..." + arr[i]);
}
}
else
{
System.out.println("It's a file");
}
}
else
{
System.out.println("Not existing");
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?