Beispiel #1
0
  /**
   * @param dbfFile A DBF file
   * @return A list of attribute names in the DBF file
   */
  public static List<String> getAttributeNames(File dbfFile) throws IOException {
    FileInputStream fis = new FileInputStream(dbfFile);
    DbaseFileReader dbfReader =
        new DbaseFileReader(fis.getChannel(), false, Charset.forName("ISO-8859-1"));

    // contains the header columns
    DbaseFileHeader dbfHeader = dbfReader.getHeader();

    // get the names from the header
    List<String> names = new Vector<String>();
    int n = dbfHeader.getNumFields();
    for (int i = 0; i < n; i++) names.add(dbfHeader.getFieldName(i));

    return names;
  }
Beispiel #2
0
  /**
   * @param dbfFile A DBF file
   * @return A list of attribute names in the DBF file
   */
  public static Object[][] getDBFData(File dbfFile) throws IOException {
    FileInputStream fis = new FileInputStream(dbfFile);
    DbaseFileReader dbfReader =
        new DbaseFileReader(fis.getChannel(), false, Charset.forName("ISO-8859-1"));

    // contains the header columns
    DbaseFileHeader dbfHeader = dbfReader.getHeader();

    List<Object[]> rowsList = new Vector<Object[]>();

    while (dbfReader.hasNext()) {
      rowsList.add(dbfReader.readEntry());
    }

    int numOfCol = dbfHeader.getNumFields();

    Object[][] dataRows = new Object[rowsList.size()][numOfCol];

    for (int i = 0; i < rowsList.size(); i++) {
      dataRows[i] = rowsList.get(i);
    }

    return dataRows;
  }