@Test
public void testfileio() throws IOException {
String f="H://Javatest/test1.txt";
String t="H://Javatest/tar.txt";
FileInputStream in=new FileInputStream(new File(f));
FileOutputStream out =new FileOutputStream(tfile);
byte[] b=new byte[3];//每次读的长度/个数--每次读三个,
int len ;
while ((len = in.read(b))!=-1) {//读
out.write(b, 0, len);//写
out.write(99);
public void testfileio() throws IOException {
String f="H://Javatest/test1.txt";
String t="H://Javatest/tar.txt";
FileInputStream in=new FileInputStream(new File(f));
FileOutputStream out =new FileOutputStream(tfile);
byte[] b=new byte[3];//每次读的长度/个数--每次读三个,
int len ;
while ((len = in.read(b))!=-1) {//读
out.write(b, 0, len);//写
out.write(99);
}
通过debug发现
执行过程是--从文件开头,读完三个,完成一个while循环;再从上一次结束位置开始再读三个,依次循环下去,直到读完
输入流in,每次读三个,放进字节数组b中,in.read(b)
输出流out,写到文件中 out.write(b, 0, len);