Skip to content

Commit

Permalink
Example: Write to DBF
Browse files Browse the repository at this point in the history
  • Loading branch information
char16t committed Aug 16, 2014
1 parent b200548 commit cf77fda
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion src/main/java/JdbfMain.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.Charset;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.iryndin.jdbf.core.DbfFileTypeEnum;
import net.iryndin.jdbf.core.DbfMetadata;
import net.iryndin.jdbf.core.DbfRecord;
import net.iryndin.jdbf.reader.DbfReader;
Expand All @@ -25,6 +30,7 @@ public static void main(String[] args) throws Exception {
//method4(args);
//method5(args);
method6(args);
method7(args);
}

public static void method5(String[] args) throws Exception {
Expand Down Expand Up @@ -82,7 +88,32 @@ public static void method6(String[] args) throws Exception {
//File file = new File("data/218864/gds_im.dbf");
testReadWriteReadFile(file);
}


/**
* Example: Write to DBF
*/
public static void method7(String[] args) throws FileNotFoundException, IOException, ParseException {
// Set metadata
String fieldsInfo = "KONTR,C,1,0|N_MDP,C,8,0";
DbfMetadata meta = DbfMetadataUtils.fromFieldsString(fieldsInfo);
meta.setType(DbfFileTypeEnum.dBASEIV3);

// Create output stream and DBF file
FileOutputStream out = new FileOutputStream("1.dbf");
DbfWriter writer = new DbfWriter(meta,out);
writer.setStringCharset("Cp866");

// Write to file
List<Map<String,Object>> maps = new ArrayList<Map<String,Object>>();
Map<String, Object> map = new HashMap<String, Object>();
map.put("KONTR", "a");
map.put("N_MDP", "2");
writer.write(map);

// The end
writer.close();
}

static void testReadWriteReadFile(File file) throws Exception {
Charset stringCharset = Charset.forName("Cp866");

Expand Down

0 comments on commit cf77fda

Please sign in to comment.