JAVA IO - RandomAccessFile
2014-01-08 00:00
369 查看
RandomAccessFile
The RandomAccessFile class in the Java IO API allows you to move around a file and read from it or write to it as you please.Here is a thing the JavaDoc forgets to mention: The read() method increments the file pointer to point to the next byte in the file after the byte just read! This means that you can continue to call read() without having to manually move the file pointer.
import java.io.RandomAccessFile; public class RandomAccessFileTest { public static void main(String args[]){ try{ RandomAccessFile file = new RandomAccessFile( "c:\\work\\hello\\helloworld.txt", "rw"); file.writeBytes("hello world!"); file.writeChar('A'); file.writeInt(1); file.writeBoolean(true); file.writeFloat(1.0f); file.writeDouble(1.0); file.close(); }catch(Exception e){ e.printStackTrace(); } } }
相关文章推荐
- 学习笔记之JavaIO中的文件处理——File和RandomAccessFile
- [学习笔记]Java基础_IO(包含对象流序列化使用和RandomAccessFile 类的使用)
- JAVA IO:RandomAccessFile
- JAVA之旅(三十)——打印流PrintWriter,合并流,切割文件并且合并,对象的序列化Serializable,管道流,RandomAccessFile,IO其他类,字符编码
- javaIO RandomAccessFile
- java.io.RandomAccessFile
- java IO(一):File、RandomAccessFile、字节流与字符流、字节字符转换流
- java零碎知识点总结 2:IO 流 --------2 RandomAccessFile
- Java IO体系之强大的RandomAccessFile
- Java_io体系之RandomAccessFile简介、走进源码及示例——20
- Java IO的RandomAccessFile的使用
- JavaIo——运用RandomAccessFile实现文件的多线程下载
- 黑马程序员--javaIO 之RandomAccessFile
- Java IO的RandomAccessFile的使用(1)
- Java IO体系之强大的RandomAccessFile
- Java IO 2:RandomAccessFile
- 【java编程】IO特殊类之RandomAccessFile实现多线程文件下载
- java.io.RandomAccessFile
- java IO之RandomAccessFile
- IO_文件分割与合并_RandomAccessFile_初始化参数_SequenceInputStreamJAVA164-167