Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
java code to split a large textfiles
Posted

1 solution

Try this
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();
}
 }
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900