按行拆分
public class Test {
private static String fileName = "G:/data.txt";
/**
*@Description: 按行分割文件
*@Author: annecheng,2019/7/11
*/
public static void splitField(int totalLine, int splitRow) {
try {
FileReader read = new FileReader(fileName);
BufferedReader br = new BufferedReader(read);
List<FileWriter> subFileList = new ArrayList<FileWriter>();
int subFileSize = totalLine % splitRow == 0 ? totalLine / splitRow : totalLine / splitRow + 1;
for (int i = 0; i < subFileSize; i++) {
subFileList.add(new FileWriter(fileName.substring(0, fileName.length() - 4) + "_" + (i + 1) + ".txt"));
}
for (Integer rowNum = 1; rowNum <= totalLine; ++rowNum) {
String row = br.readLine();