思路:
1、将dbf文件数据读出后,在用insert语句插入。效率太低,所以舍弃
2、将dbf文件数据写入txt文件中,然后用LOAD DATA INFILE 直接导入到数据库中
具体代码:
1、创建一个DBFReader
import java.io.DataInputStream;
import java.io.EOFException;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
public class DBFReader
{
private DataInputStream stream = null;
private JDBField[] fields = null;
private byte[] nextRecord = null;
public DBFReader(String paramString)
throws
com.svcon.jdbf.JDBFException
{
try
{
init(new FileInputStream(paramString));
}
catch
(FileNotFoundException localFileNotFoundException)
{
throw new
com.svcon.jdbf.JDBFException(localFileNotFoundException);
}
}
public DBFReader(InputStream
paramInputStream)
throws
com.svcon.jdbf.JDBFException
{
init(paramInputStream);
}
private void init(InputStream
paramInputStream)
throws
com.svcon.jdbf.JDBFException
{
try
{
this.stream = new DataInputStream(paramInputStream);
int i = readHeader();
this.fields = new JDBField[i];
int j = 1;
for (int k = 0; k < i; ++k)
{
this.fields[k] = readFieldHeader();
j += this.fields[k].getLength();
}
if (this.stream.read() < 1)
throw new com.svcon.jdbf.JDBFException("Unexpected end of file
reached.");
this.nextRecord = new byte[j];
try
{
this.stream.readFully(this.nextRecord);
}
catch (EOFException localEOFException)
{
this.nextRecord = null;
this.stream.close();
}
}
catch
(IOException localIOException)
{
throw new com.svcon.jdbf.JDBFException(localIOException);
}
}
private int readHeader()
throws
IOException, com.svcon.jdbf.JDBFException
{
byte[]
arrayOfByte = new byte[16];
try
{
this.stream.readFully(arrayOfByte);
}
catch
(EOFException localEOFException1)
{
throw new com.svcon.jdbf.JDBFException("Unexpected end of file
reached.");
}
int i =
arrayOfByte[8];
if (i
< 0)
i += 256;
i += 256