• java 导出dbf格式


    java 导出dbf 格式

    demo地址:https://github.com/woyaochengweidaniu/javaEE/tree/master/file-handling
    参考文章:http://priede.bf.lu.lv/ftp/pub/DatuBazes/DBF/javadbf/javadbf-tutorial.html

    依赖

    <!-- https://mvnrepository.com/artifact/com.github.albfernandez/javadbf -->
            <dependency>
                <groupId>com.github.albfernandez</groupId>
                <artifactId>javadbf</artifactId>
                <version>1.9.4</version>
            </dependency>
    

    导出dbf

    package com.example.easyexcel.dbf;
    
    import com.linuxense.javadbf.DBFDataType;
    import com.linuxense.javadbf.DBFException;
    import com.linuxense.javadbf.DBFField;
    import com.linuxense.javadbf.DBFWriter;
    
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.nio.charset.Charset;
    
    /**
     * javadbf包   导入导出
     *
     * 参考文章:http://priede.bf.lu.lv/ftp/pub/DatuBazes/DBF/javadbf/javadbf-tutorial.html
     * @author lcm
     */
    public class DBFWriterTest {
    
        public static void main( String args[])
                throws DBFException, IOException {
    
            // let us create field definitions first
            // we will go for 3 fields
            //
            DBFField fields[] = new DBFField[ 3];
    
            fields[0] = new DBFField();
            fields[0].setName( "emp_code");
            fields[0].setType(DBFDataType.CHARACTER);
            fields[0].setLength( 10);
    
            fields[1] = new DBFField();
            fields[1].setName( "emp_name");
    
            fields[1].setType(DBFDataType.CHARACTER);
            fields[1].setLength( 20);
    
            fields[2] = new DBFField();
            fields[2].setName( "salary");
            fields[2].setType(DBFDataType.FLOATING_POINT );
            fields[2].setLength( 12);
            fields[2].setDecimalCount( 2);
    
            FileOutputStream fos = new FileOutputStream("C:\temp\test.dbf");
            DBFWriter writer = new DBFWriter(fos, Charset.defaultCharset());
            writer.setFields( fields);
    
            // now populate DBFWriter
            //
    
            Object[] rowData = new Object[3];
            rowData[0] = "1000";
            rowData[1] = "John";
            rowData[2] = 5000.00;
    
            writer.addRecord( rowData);
    
            rowData = new Object[3];
            rowData[0] = "1001";
            rowData[1] = "Lalit";
            rowData[2] = 3400.00;
    
            writer.addRecord( rowData);
    
            rowData = new Object[3];
            rowData[0] = "1002";
            rowData[1] = "Rohit";
            rowData[2] = 7350.00;
    
            writer.addRecord( rowData);
            writer.close();
            fos.close();
        }
    }
    
    
    

    导入dbf

    package com.example.easyexcel.dbf;
    
    import com.linuxense.javadbf.DBFException;
    import com.linuxense.javadbf.DBFField;
    import com.linuxense.javadbf.DBFReader;
    
    import java.io.FileInputStream;
    import java.io.IOException;
    import java.io.InputStream;
    
    public class JavaDBFReaderTest {
    
        public static void main( String args[]) {
    
            try {
    
                // create a DBFReader object
                //
                InputStream inputStream  = new FileInputStream( args[ 0]); // take dbf file as program argument
                DBFReader reader = new DBFReader( inputStream);
    
                // get the field count if you want for some reasons like the following
                //
                int numberOfFields = reader.getFieldCount();
    
                // use this count to fetch all field information
                // if required
                //
                for( int i=0; i<numberOfFields; i++) {
    
                    DBFField field = reader.getField( i);
    
                    // do something with it if you want
                    // refer the JavaDoc API reference for more details
                    //
                    System.out.println( field.getName());
                }
    
                // Now, lets us start reading the rows
                //
                Object []rowObjects;
    
                while( (rowObjects = reader.nextRecord()) != null) {
    
                    for( int i=0; i<rowObjects.length; i++) {
    
                        System.out.println( rowObjects[i]);
                    }
                }
    
                // By now, we have itereated through all of the rows
    
                inputStream.close();
            }
            catch( DBFException e) {
    
                System.out.println( e.getMessage());
            }
            catch( IOException e) {
    
                System.out.println( e.getMessage());
            }
        }
    }
    
    
  • 相关阅读:
    #include <functional>
    3.3内联函数
    如何查看内存占用和运行速度
    属性和方法的动态绑定和限制
    __slots__节约空间
    函数进阶之一等对象
    python继承之super
    python的方法VSjava方法
    python面向对象基础(三)内置方法 __xx__
    python面向对象基础(二)反射
  • 原文地址:https://www.cnblogs.com/java-hardly-road/p/11158191.html
Copyright © 2020-2023  润新知