File用来封装路径,可以是文件路径,也可以是目录路径,也可以是不存在的路径。
File创建对象有两种方式:
1.File f = new File(“d:\acb\a.txt”);
2.File f = new File(“d:\acb\”,”a.txt”);
File有很多方法,文件和目录的属性:
eg:canRead() acnWrite() canExexute()
isHide()
exists()
getAbsolutePath()
getName()
getParent()
lastModified() 最后修改时间
length() 文件子节量面对目录无效
isDirectory()
isFile()
getTotalSpace()
getFreeSpace()
等;
文件和目录的操作:
createNewFile()
delete()
mkdir() 创建单层目录
renameTo() 改名移到
文件列表:
list() 返回String[],包含子文件、子目录名称
listFile() 返回File[],包含子文件,子目录的File的名称
list(FilenameFilter)
listFiles(FilenameFilter)
listFiles(FileFilter) 只列出符合过滤条件的文件目录,参数是外接的文件。
java.io.RandomAccessFile 读写文件的工具
创建对象:
1.RandomAccessFile raf = new RandomAccessFile(文件,“rw”); 读写
2.RandomAccessFile raf = new RandomAccessFile(文件,“r”); 只读
方法:
write(int a) int四个字节只输出末尾的一个字节值,如图:
未完待续。。。。。。。