public class Ja {
public static void main (String args[])throws IOException{
File files=new File("D:/all_2012-03-28.txt");
FileReader readfile=new FileReader(files);
BufferedReader buffer=new BufferedReader(readfile);
String s;
System.out.println(DateUtil.getStandardTime());
int i=0;
int m=0;//全量文件行数
int ge=0;//新生成文件个数
StringBuffer fileContent = new StringBuffer();
while((s=buffer.readLine())!=null){
File file=null;
// for( int i=0;i<tlist.size();i++){
if(ge==0){
file = new File("D://logs//all_2012-03-28_"+ge+".txt"); //生成第一个分段全量新文件
if(!file.getParentFile().exists()){
file.mkdir();
}
ge++;
}
fileContent.append(s.toString());
fileContent.append(System.getProperty("line.separator")); //System.getProperty("line.separator")获取行分隔符(如“/n”)
write(fileContent.toString(), "D://logs//all_2012-03-28_"+(ge-1)+".txt","UTF-8");//写入分段全量新文件
if(m==20000){
m=0;
file = new File("D://logs//gall_2012-03-28_"+ge+".txt"); //生成分段全量新文件
if(!file.getParentFile().exists()){
file.mkdir();
}
ge++;
fileContent=null;
fileContent= new StringBuffer();
}
m++;
}
System.out.println("ok"+i);
System.out.println(DateUtil.getStandardTime());
}
/**
* 以utf-8格式写文件
* @param fileContent
* @param fileName
* @param encoding
*/
public static void write(String fileContent, String fileName, String encoding) {
try {
FileOutputStream fos = new FileOutputStream(fileName);
OutputStreamWriter osw = new OutputStreamWriter(fos, encoding);
osw.write(fileContent);
osw.flush();
} catch (Exception e) {
e.printStackTrace();
}
}
}
public static void main (String args[])throws IOException{
File files=new File("D:/all_2012-03-28.txt");
FileReader readfile=new FileReader(files);
BufferedReader buffer=new BufferedReader(readfile);
String s;
System.out.println(DateUtil.getStandardTime());
int i=0;
int m=0;//全量文件行数
int ge=0;//新生成文件个数
StringBuffer fileContent = new StringBuffer();
while((s=buffer.readLine())!=null){
File file=null;
// for( int i=0;i<tlist.size();i++){
if(ge==0){
file = new File("D://logs//all_2012-03-28_"+ge+".txt"); //生成第一个分段全量新文件
if(!file.getParentFile().exists()){
file.mkdir();
}
ge++;
}
fileContent.append(s.toString());
fileContent.append(System.getProperty("line.separator")); //System.getProperty("line.separator")获取行分隔符(如“/n”)
write(fileContent.toString(), "D://logs//all_2012-03-28_"+(ge-1)+".txt","UTF-8");//写入分段全量新文件
if(m==20000){
m=0;
file = new File("D://logs//gall_2012-03-28_"+ge+".txt"); //生成分段全量新文件
if(!file.getParentFile().exists()){
file.mkdir();
}
ge++;
fileContent=null;
fileContent= new StringBuffer();
}
m++;
}
System.out.println("ok"+i);
System.out.println(DateUtil.getStandardTime());
}
/**
* 以utf-8格式写文件
* @param fileContent
* @param fileName
* @param encoding
*/
public static void write(String fileContent, String fileName, String encoding) {
try {
FileOutputStream fos = new FileOutputStream(fileName);
OutputStreamWriter osw = new OutputStreamWriter(fos, encoding);
osw.write(fileContent);
osw.flush();
} catch (Exception e) {
e.printStackTrace();
}
}
}