資源簡介
java按行讀取大容量文本文件,并按行解析入庫。使用java.nio下面的相關方法
代碼片段和文件信息
package?big;
import?java.io.File;
import?java.io.IOException;
import?java.io.RandomAccessFile;
import?java.nio.ByteBuffer;
import?java.nio.channels.FileChannel;
import?java.nio.charset.Charset;
import?java.util.ArrayList;
import?java.util.Arrays;
import?java.util.List;
public?class?BigFileRead??{
????
private?File?cfFile?=?null;
Charset?charset?=?Charset.forName(“GB2312“);//?創建GBK字符集?
???
?
RandomAccessFile?raf=??null;
FileChannel?fc=null;
????List?lc=new?ArrayList();
????
public?BigFileRead(File?cfFileString?charset)?throws?IOException?{
super();
this.cfFile?=?cfFile;
this.charset=?Charset.forName(charset);
raf?=?new?RandomAccessFile(this.cfFile“r“);
init();
}
private?void?init()?throws?IOException?{
fc=raf.getCh
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2015-01-30?14:24??java讀取大文件\
?????文件????????2396??2015-01-30?10:05??java讀取大文件\BigFileRead.java
?????文件????????4763??2015-01-30?14:23??java讀取大文件\TestQ.java
評論
共有 條評論