F ile类是IO包中唯一代表磁盘文件本身信息的类,而不是文件本身的内容。
编程举例:
import java.io.*;
public class FileTest()
{
public static void main(String[] args )
{
File f=new File("1.txt");
if(f.exists())
{
f.delete();
}
else{
f.createNewFile();
}
System.out,println("File name:"+f.getName());
}
}
---
System.out,println("File path:"+f.getPath());//路径
System.out,println("File abs path:"+f.getAbsolutePath());//绝对路径
System.out,println(f.exists()?"exists":"not exists");
本文介绍Java中File类的基本使用方法,包括创建文件、检查文件是否存在及删除文件等操作,并提供了一个简单的示例程序来演示这些功能。
850

被折叠的 条评论
为什么被折叠?



