public static void sqlitFileDate(String filepath, String sqlitPath,
int CountFile) throws IOException {
FileWriter fs = null;
BufferedWriter fw=null;
FileReader fr = new FileReader(filepath + "\\question_pic.sql");
BufferedReader br = new BufferedReader(fr); // 读取获取整行数据
int i = 1;
LinkedList WriterLists=new LinkedList(); //初始化文件流对象集合
LinkedList fwLists=new LinkedList();
for (int j = 1; j <= CountFile; j++) {
//声明对象
fs = new FileWriter(sqlitPath + "\\12" + j + ".txt",false);
fw=new BufferedWriter(fs);
//将对象装入集合
WriterLists.add(fs);
fwLists.add(fw);
}
//判断是文件流中是否还有数据返回
while (br.ready()) {
int count=1;//初始化第一文件流
for (Iterator iterator = fwLists.iterator(); iterator.hasNext();) {
BufferedWriter type = (BufferedWriter) iterator.next();
if(i==count)//判断轮到第几个文件流写入数据了
{
//写入数据,跳出,进行下一个文件流,下一个数据的写入
type.write(br.readLine() + "\r\n");
break;
}
count++;
}
//判断是否到了最后一个文件流了
if (i >= CountFile) {
i = 1;
} else
i++;
}
br.close();
fr.close();
for (Iterator iterator = fwLists.iterator(); iterator.hasNext();) {
BufferedWriter object = (BufferedWriter) iterator.next();
object.close();
}
//遍历关闭所有子文件流
for (Iterator iterator = WriterLists.iterator(); iterator.hasNext();) {
FileWriter object = (FileWriter) iterator.next();
object.close();
}
}
split file
最新推荐文章于 2024-03-15 15:14:03 发布