62,623
社区成员
发帖
与我相关
我的任务
分享d.writeBytes(copyline);//后面加一句 d.writeChars("\n");
public class InputFile {
/**
* @param the start of pre_process
* @throws IOException
*/
public static void main(String[] args) throws IOException {
FileCut in=new FileCut("E:/temp/test.txt");//创建一个fileCut对象 in
in.inputfile();
}
}
public class FileCut implements RandomAccess {
private String filetrack;
private String copyline;
public FileCut(String string) {
// TODO 传入文件路径
this.filetrack = string;
}
void inputfile() throws IOException {
// TODO 创建RandomAccessFile类型对象, 并读取文件
File track = new File(filetrack);
RandomAccessFile sourcefile = new RandomAccessFile(track, "r");
System.out.println("I have read it");
int t = 1;
for (int i = 0; i < 10; i++) { // 十次循环,每次新建一个文件
int count = 0;
DataOutputStream d = new DataOutputStream(new FileOutputStream(
"E:/" + (t++) + ".txt"));
while (count < 50) { // 循环将58行写入一个文件
copyline = sourcefile.readLine();
d.writeBytes(copyline);
count++;
}
d.close();
}
}
}