阅读背景:

RandomAccessFile使用示例

来源:互联网 
	public static void method1() {
		RandomAccessFile aFile = null;
		try {
			aFile = new RandomAccessFile("D:\\var\\demo.txt", "rw");
			FileChannel fileChannel = aFile.getChannel();
			ByteBuffer buf = ByteBuffer.allocate(1024);
			int bytesRead = fileChannel.read(buf);
			System.out.println(bytesRead);
			while (bytesRead != -1) {
				buf.flip();
				while (buf.hasRemaining()) {
					System.out.print((char) buf.get());
				}
				buf.compact();
				bytesRead = fileChannel.read(buf);
			}
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				if (aFile != null) {
					aFile.close();
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}	public static void method1() {
		Rand



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: