Because it involves reading data from large files, but the program memory is too small to read the reason, so the file is split to read
Package cn.jado.ctt_check.test;
Import Java.io.BufferedReader;
Import Java.io.FileInputStream;
Import java.io.FileNotFoundException;
Import java.io.IOException;
Import Java.io.InputStreamReader;
Import java.io.UnsupportedEncodingException;
Import java.util.ArrayList;
Import java.util.List;
Import Org.apache.log4j.Logger;
Import Cn.jado.ctt_check.util.IOUtil;
public class Spiltfile {
private static final Logger Logger = Logger.getlogger (Spiltfile.class);
public static void Main (string[] args) {String path = ' f:/usr/local/statistic/utf-8_20170221_wechat_article.
DATA ";
Readfilebylinetolist (Path, "Utf-8"); /*** * Split a large file into 1,000,001 files * @author Jado * @param fileName * @param charsetname * @return/public static LIST&L T String> readfilebylinetolist (String filename,string charsetname) {list<string> linelist = new ArrayList<St
Ring> ();
String path = Ioutil.pathparser (fileName) [0]+ "/wechat_msg/";
Ioutil.mkdirs (path);
if (CharsetName = = null) {CharsetName = System.getproperty ("file.encoding");
} BufferedReader br = null;
InputStreamReader isreader = null;
try {if (CharsetName = = null) {CharsetName = System.getproperty ("file.encoding");
} Isreader = new InputStreamReader (new FileInputStream (FileName), charsetname);
br = new BufferedReader (Isreader);
String tempstring = null;
int v = 0; while ((tempstring = Br.reAdline ())!= null) {v+=1;
Millions data into a file Linelist.add (tempstring); if (v%100000==0) {for (String line:linelist) {ioutil.writefile (path+v+) _wechat_article.
DATA ", line+" \ n "," Utf-8 ", true);
} linelist.clear (); '} ' catch (Unsupportedencodingexception E1) {//TODO auto-generated catch block Logger.erro
R ("Parsing file Encoding exception", E1);
catch (FileNotFoundException E2) {//TODO auto-generated catch block Logger.error ("File not found exception", E2);
The catch (IOException E3) {//TODO auto-generated catch block Logger.error ("IO Operation exception", E3);
}finally{if (br!= null) {try {br.close ();
br = NULL;
catch (IOException e4) {//TODO auto-generated catch block Logger.error ("File Shutdown exception", E4); } if (IsreaDer!= null) {try {isreader.close ();
catch (IOException e5) {//TODO auto-generated catch block Logger.error ("File Shutdown exception", E5);
}} return linelist;
}
}