public static void main ( String [ ] args ) { if ( args . length < 1 ) { System . out . println ( "filename or URL required" ) ; System . exit ( - 1 ) ; } for ( String s : args ) { System . out . println ( "*** Dump of Dbase " + s + ":" ) ; try { DbaseFile dbf = new DbaseFile ( s ) ; // load() method reads all data at once if ( dbf . loadHeader ( ) != 0 ) { System . out . println ( "Error loading header" + s ) ; System . exit ( - 1 ) ; } // output schema as [type0 field0, type1 field1, ...] String [ ] fieldNames = dbf . getFieldNames ( ) ; System . out . print ( "[" ) ; int nf = dbf . getNumFields ( ) ; DbaseData [ ] dbd = new DbaseData [ nf ] ; for ( int field = 0 ; field < nf ; field ++ ) { dbd [ field ] = dbf . getField ( field ) ; switch ( dbd [ field ] . getType ( ) ) { case DbaseData . TYPE_BOOLEAN : System . out . print ( "boolean " ) ; break ; case DbaseData . TYPE_CHAR : System . out . print ( "String " ) ; break ; case DbaseData . TYPE_NUMERIC : System . out . print ( "double " ) ; break ; } System . out . print ( fieldNames [ field ] ) ; if ( field < nf - 1 ) System . out . print ( ", " ) ; } System . out . println ( "]" ) ; if ( dbf . loadData ( ) != 0 ) { System . out . println ( "Error loading data" + s ) ; System . exit ( - 1 ) ; } // output data for ( int rec = 0 ; rec < dbf . getNumRecords ( ) ; rec ++ ) { for ( int field = 0 ; field < nf ; field ++ ) { System . out . print ( dbd [ field ] . getData ( rec ) ) ; if ( field < nf - 1 ) System . out . print ( ", " ) ; else System . out . println ( ) ; } } } catch ( IOException e ) { e . printStackTrace ( ) ; break ; } } }
Test program dumps a Dbase file to stdout .