这是一张今天所学的流的大致的总结.
下面是每一种流的具体代码
RandomAccessFile(可读可写)
这个流名字上没有什么区分度,但是从他的操作上来说应该算是字符流
RandomAccessFile raf= null;
try {
raf = new RandomAccessFile("D:"+File.separator+"demo.txt","rw");
long l = raf.getFilePointer();
System.out.println("指针得位置是:"+l);
raf.write("西瓜没有毛".getBytes());
l = raf.getFilePointer();
System.out.println("指针得位置是:"+l);
System.out.println("写出完毕!");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
try {
raf.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
raf.write("西瓜没有毛".getbyte);写
raf.readline();返回一个字符串,读一行
raf.seek(6);设置指针,从第6个位置开