分割文本文件的Java代码 [英] java code to split a textfile

查看:156
本文介绍了分割文本文件的Java代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用于拆分大文本文件的Java代码

java code to split a large textfiles

推荐答案

尝试一下
import java.io.*;
import java.util.Scanner;
 
public class FileRead {
public static void main(String[] args) throws IOException
 {
StringBuffer strBuff = new StringBuffer();
String str = null;
 
File file = new File("test.txt");
try {
Scanner scanner = new Scanner(file);
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
Scanner lineScanner = new Scanner(line);
lineScanner.useDelimiter("");
while (lineScanner.hasNext()) {
String part = lineScanner.next();
if(!part.equals(" "))
strBuff.append(part);
if(strBuff.length() == 5){
System.out.println("strBuff= "+strBuff.toString());
strBuff.delete(0,strBuff.length());
}
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
 }
}


这篇关于分割文本文件的Java代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆