目标:实现从from.txt文件中(大量内容)读入数据,并写入to.txt文件中
代码:
package nihao;
import java.io.FileInputStream;
import java.io.FileOutputStream;
public class Nihao {
public static void main(String[] args) {
FileInputStream fis = null;
FileOutputStream fos = null;
try {
fis = new FileInputStream("c:\\from.txt");
fos = new FileOutputStream("c:\\to.txt");
byte[] butter = new byte[1024];
while (true) {
int temp = fis.read(butter, 0, butter.length);
for (int i = 0; i < temp; i++) {
System.out.println(butter[i]);
}
if (temp == -1) {
break;
}
fos.write(butter, 0, temp);
}
} catch (Exception e) {
System.out.println(e);
}
}
}