输出流

11.13

今天练习了输出流的代码:

代码部分:

package lianxi;
import java.io.*;
public class bo
{
public static void main(String[] args) throws IOException {
FileInputStream fis = null;
FileOutputStream fos = null;
try {
//创建字节输入流
fis = new FileInputStream("D://b.txt");
//创建字节输入流
fos = new FileOutputStream("D://c.txt");
byte[] bbuf = new byte[32];
int hasRead = 0;
//循环从输入流中取出数据
while ((hasRead = fis.read(bbuf)) > 0) {
//每读取一次,即写入文件输出流,读了多少,就写多少。
fos.write(bbuf, 0, hasRead);
}
} catch (IOException ioe) {
ioe.printStackTrace();
} finally {
//使用finally块来关闭文件输入流
if (fis != null) {
fis.close();
}
//使用finally块来关闭文件输出流
if (fos != null) {
fos.close();
}
}
}
}

 运行结果:

 

 

 

 

 

 运行结果分析:

成功的吧b文件里的内容输入道了c文件里

posted @ 2020-11-13 10:30  潘福龙  阅读(82)  评论(0编辑  收藏  举报