import java.io.*;
public class IOTest {
public static void main(String[] args) throws Exception {
File f1 = new File("x1.txt");
File f2 = new File("x2.txt");
InputStream is = new FileInputStream(f1);
OutputStream os = new FileOutputStream(f2, true);
byte[] buf = new byte[1024];
int len = 0;
while((len=is.read(buf)) != 0) {
if(len > 0) {
os.write(buf,0,len);
}
if(f2.length() == f1.length()*3) {
break;
}
}
os.close();
is.close();
}
}
x1.txt的内容如下:
something is wrong.
x2.txt的内容是什么啊?为什么?
每次读指针读到末尾会自动跳到0位置? |
|