黑马程序员 java IO 分割文件

来源:互联网 发布:c语言多进程编程 编辑:程序博客网 时间:2024/06/05 22:45
package itcast.video0101;


import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.SequenceInputStream;
import java.util.Vector;


public class I_13_IO_SplitFile {


/**
* @param args
* @throws FileNotFoundException
*/
public static void main(String[] args) throws IOException {
splitFile();
}


public static void splitFile() throws IOException {
FileInputStream fis = new FileInputStream("f:\\itcastVideo.\\add.txt");
FileOutputStream fos = null;
byte[] by = new byte[100];
int len = 0;
int count = 1;
while ((len = fis.read(by)) != -1) {
fos = new FileOutputStream("f:\\itcastVideo.\\split" + (count++)+ ".part");
fos.write(by,0,len);
fos.close();
}
fis.close();
}
}
0 0
原创粉丝点击