package com.webserver.core;

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

/**
 * 显示所有用户信息
 * @author soft01
 *
 */
public class ShowAllUserDemo {
	public static void main(String[] args) throws IOException{
		RandomAccessFile raf = new RandomAccessFile("user.dat","r");
		
		for(int i = 0;i<raf.length()/100;i++) {
			//读取用户名
			byte[] data = new byte[32];//代表32位的字节数组
			raf.read(data);//读取
			/*将读取的(二进制)byte数组按照UTF-8字符集编译成相应的字符串 
			 * 并去除空白字符
			 */
			String username = new String(data,"UTF-8").trim();
			
			//读取密码
			raf.read(data);
			String password = new String(data,"UTF-8").trim();
			
			//读取昵称
			raf.read(data);
			String nickname = new String(data,"UTF-8").trim();
			
			//读取年龄
			int age = raf.readInt();
			System.out.println(username+","+password+","+nickname+","+age);
			
		}
		System.out.println("point:"+raf.getFilePointer());//此时文件指针的位置(代表此时文件的字节数)

		raf.close();
		
	}

}
最近下载更多
yhtech2015  LV8 2019年8月26日
zuidaima005  LV10 2019年6月6日
可是不知道么  LV23 2019年5月17日
qq1453363097  LV13 2019年4月24日
浪子在路上  LV12 2019年4月22日
zuidaima21533  LV1 2019年4月19日
sunliwei  LV8 2019年4月19日
小牧34556  LV8 2019年4月17日
最代码官方  LV167 2019年4月12日
最近浏览更多
wan4444  LV1 2023年6月29日
qq232323 2023年5月29日
暂无贡献等级
哼哈二将哈哈哈哈啊哈 2022年12月20日
暂无贡献等级
Murmure  LV2 2022年12月9日
crosa_Don  LV18 2022年6月7日
gqb0123  LV1 2022年4月8日
a5366869  LV7 2021年10月31日
是pangpang呀  LV6 2021年7月10日
ericxu1116  LV24 2021年6月26日
pxqtsht  LV15 2021年6月18日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友