当前位置: 首页 > news >正文

DBASE DBF数据库文件解析

基于Java实现DBase DBF文件的解析和显示

JDK19编译运行,实现了数据库字段和数据解析显示。

首先解析数据库文件头代码

		byte bytes[] = Files.readAllBytes(Paths.get(file));BinaryBufferArray bis = new BinaryBufferArray(bytes);DBF dbf = new DBF();dbf.VersionNumber = bis.ReadUInt8();		// 版本号dbf.DateOfLastUpdate = bis.ReadBytes(3);  	// 最后更新日期dbf.NumberOfRecords = bis.ReadUInt32();		// 记录数量dbf.LengthOfHeaderStructure = bis.ReadUInt16();	// 文件头长(内容开始位置)dbf.LengthOfEachRecord  = bis.ReadUInt16();	// 每条记录长度short Reserved = bis.ReadInt16();dbf.IncompleteTransac = bis.ReadUInt8();	dbf.EncryptionFlag = bis.ReadUInt8();dbf.FreeRecordThread = bis.ReadInt32();long ReservedForMultiUser= bis.ReadInt64();dbf.MDXFlag = bis.ReadUInt8();dbf.LanguageDriver = bis.ReadUInt8();	Reserved = bis.ReadInt16();

解析字段代码

		dbf.fields = new Vector<Field>();while (true) {byte _b = bis.ReadInt8();if (_b == 0x0d) 	// 是否结束break ;byte[] bs = bis.ReadInt8(31);byte[] all = new byte[32];all[0] = _b;System.arraycopy(bs, 0, all, 1, 31);Field field = Field.parse(all);	dbf.fields.add(field);}
	static Field parse(byte[] b) throws IOException  {Field field = new Field();BinaryBufferArray t = new BinaryBufferArray(b);field.name = t.ReadAsciiString(11).trim();	//字段名称field.type = t.ReadAsciiChar();				// 字段类型t.SkipBytes(4);field.length = t.ReadUInt8();				// 字段长度field.precision = t.ReadUInt8();			// 精度t.SkipBytes(2);field.id = t.ReadUInt8();t.SkipBytes(10);field.mdx = t.ReadUInt8();return field;}

解析数据代码:

		dbf.resultset = new Vector<Map<String, Object>>();	//结果集for (int i=0; i<dbf.NumberOfRecords-1; i++) {char delete = '\0';		delete = bis.ReadAsciiChar();	// 读入删除标记HashMap<String,Object> map = new HashMap<>();for (int j=0; j<dbf.fields.size(); j++) {Field field = dbf.fields.get(j);char type = field.getType();int len = field.getLength();Object val = null;byte[] b = bis.ReadBytes(len);	//读取字段值if (field.getType() == 'N')val = new String(b);else if (field.getType() =='C')val = new String(b, "UTF-8");map.put(field.getName(), val);}map.put("delete", delete);dbf.resultset.add(map);}

读入dbf文件,解析显示如下:

http://www.lryc.cn/news/532147.html

相关文章:

  • html基本结构和常见元素
  • JAVAweb学习日记(十) Mybatis入门操作
  • 从Transformer到世界模型:AGI核心架构演进
  • Rk3588芯片介绍(含数据手册)
  • java开发面试自我介绍模板_java面试自我介绍3篇
  • w193基于Spring Boot的秒杀系统设计与实现
  • chrome浏览器chromedriver下载
  • 【HTML入门】Sublime Text 4与 Phpstorm
  • Python----Python高级(并发编程:进程Process,多进程,进程间通信,进程同步,进程池)
  • 汽车自动驾驶AI
  • Linux之安装MySQL
  • 说说Redis的内存淘汰策略?
  • SQL范式与反范式_优化数据库性能
  • 从BIO到NIO:Java IO的进化之路
  • Mysql:数据库
  • 深度学习系列--01.入门
  • 【Elasticsearch】`auto_date_histogram`聚合功能详解
  • php7.3安装php7.3-gmp扩展踩坑总结
  • 7. k8s二进制集群之Kube ApiServer部署
  • QT笔记——多语言翻译
  • 【2025】camunda API接口介绍以及REST接口使用(3)
  • js面试some和every的区别
  • Vue 中如何嵌入可浮动的第三方网页窗口(附Demo)
  • 【大数据技术】词频统计样例(hadoop+mapreduce+yarn)
  • java进阶知识点
  • 深度学习系列--02.损失函数
  • 构建一个数据分析Agent:提升分析效率的实践
  • 在K8S中,如何把某个worker节点设置为不可调度?
  • 硬件电路基础
  • 5 前端系统开发:Vue2、Vue3框架(上):Vue入门式开发和Ajax技术