java 기초 --- - RandomAccessFile

1094 단어 Java
package com.cug.datastream;

import java.io.IOException;
import java.io.RandomAccessFile;

public class RandomAccessFileDemo {
	public static void main(String[] args) throws IOException {
		writer();
		reader();
	}
	
	public static void reader() throws IOException{
		RandomAccessFile raf = new RandomAccessFile("r.txt", "r");
		System.out.println(raf.getFilePointer());//0
		System.out.println(raf.readInt()+":"+raf.getFilePointer());//12:4
		System.out.println(raf.readChar()+":"+raf.getFilePointer());//c:6
		System.out.println(raf.readUTF()+":"+raf.getFilePointer());//  :14
		raf.close();
	}
	
	public static void writer() throws IOException{
		RandomAccessFile raf = new RandomAccessFile("r.txt", "rw");
		raf.writeInt(12);
		raf.writeChar('c');
		raf.writeUTF("  ");
		
		raf.close();
	}
}


좋은 웹페이지 즐겨찾기