首页 > 其他分享 >字节流拷备文档 学会了可以拷一切 1216

字节流拷备文档 学会了可以拷一切 1216

时间:2022-12-16 16:35:37浏览次数:41  
标签:java 字节 bytes xsRead len io 流拷备 1216

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class Test2 {
public static void main(String[] args) throws IOException {
// 获取字节输入流
FileInputStream xsRead = new FileInputStream("小说.txt");
// 获取字节数组
byte[] bytes = new byte[200];
// 获取字节输出流
FileOutputStream xsWrite = new FileOutputStream("小说_字节_拷备.txt");
// 遍历读字节
int len = xsRead.read(bytes);
while (len != -1) {
// 代码来到这里 意味羞容器中有数据
// 立马写数据
xsWrite.write(bytes, 0, len);
// 游戏移动
len = xsRead.read(bytes);
}
// 关资源
xsWrite.close();
xsRead.close();
// 程序结束
System.out.println("game over");
}
}

标签:java,字节,bytes,xsRead,len,io,流拷备,1216
From: https://blog.51cto.com/u_13137233/5947765

相关文章