当前位置:我的异常网» 编程 » java瓜分txt全量文件
java瓜分txt全量文件
java分割txt全量文件
public class Ja {
public static void main (String args[])throws IOException{
File files=new File("D:/");
FileReader readfile=new FileReader(files);
BufferedReader buffer=new BufferedReader(readfile);
String s;
System.out.StandardTime());
int i=0;
int m=0;//全量文件行数
int ge=0;//新生成文件个数
StringBuffer fileContent = new StringBuffer();
while((sadLine())!=null){
File file=null;
// for( int i=0;i
if(ge==0){
file = new File("D://logs//all_2012-03-28_"+ge+".txt"); //生成第一个分段全量新文件
if(!ParentFile().exists()){
file.mkdir();
}
ge++;
}
fileContent.String());
fileContent.Property("line.separator")); //Property("line.separator")获取行分隔符(如“/n”)
String(), "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(!ParentFile().exists()){
file.mkdir();
}
ge++;
fileContent=null;
fileContent= new StringBuffer();
}
m++;
}
System.out.println("ok"+i);
System.out.StandardTime());
}
/**
* 以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();
}
}
}
文章评论
本文发布于:2024-01-29 04:16:07,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170647297412629.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |