public class Main { public static void main(String[] args) { BufferedReader br = null; BufferedWriter bw = null; int count = 0; int index = 1; String temp = ""; try { br = new BufferedReader(new FileReader(new File("F:\\result.txt"))); while((temp = br.readLine()) != null){ bw = new BufferedWriter(new FileWriter(new File("F:\\output"+(index++)+".txt"))); while(count < 100000){ bw.append(temp); bw.newLine(); count++; temp = br.readLine(); if(temp == null){ break; } } count = 0; bw.close(); } br.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }
假设result.txt有200多万行。