写操作,见如下代码:
DBFField fields[] = new DBFField[3]; // S1 HQZQDM 证券代码 Char 6 fields[0] = new DBFField(); fields[0].setName("HQZQDM"); fields[0].setDataType(DBFField.FIELD_TYPE_C); fields[0].setFieldLength(100); // S2 HQZQJC 证券名称 Char 8 fields[1] = new DBFField(); fields[1].setName("HQZQJC"); fields[1].setDataType(DBFField.FIELD_TYPE_C); fields[1].setFieldLength(8); // S3 HQZRSP 前收盘价格 Num 8 3 fields[2] = new DBFField(); fields[2].setName("HQZRSP"); fields[2].setDataType(DBFField.FIELD_TYPE_N); fields[2].setFieldLength(10); DBFWriter writer = new DBFWriter(); writer.setFields(fields); Object a[] = new Object[3]; Pattern pWord = Pattern.compile("[\u4e00-\u9fa5]");// 校验中文的正则表达式 String value = "木耳"; int m = value.getBytes().length; String blank = ""; if (pWord.matcher(value).find()) {// 如果包含中文就要补够2倍中文字数个空格,否则会导致中文乱码 for (int j = 0; j < m; j++) { blank += " "; } } a[0] = value + blank; a[1] = ""; a[2] = new Integer(12).doubleValue(); writer.setCharactersetName("GB2312"); writer.addRecord(a); FileOutputStream fos = new FileOutputStream("PENGBO.dbf"); writer.write(fos); fos.close();