代码示例如下:
//RandomAccessFile 读文件
String line=null;
int count=0;
try {
RandomAccessFile raf=new RandomAccessFile("G:/hdf5_write_txt/a0901.txt", "r");
while(null != (line=raf.readLine())) {//读到数据
line=new String(line.getBytes("UTF-8"),"GBK");
// System.out.println(line+","+line.length());//得到每条数据的字符串长度
count+=1;
}
System.out.println("本次读出的数据共"+count+"条");
raf.close()
} catch (Exception e) {
e.printStackTrace();
}