初学Java IO之使用FileOutputStream和FileWriter写入文件 四十二

分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

               
import java.io.*;public class FileOutputStreamTest public static void main(String[] args) throws IOException {  FileInputStream fis = null;  FileOutputStream fos = null;  try  {   //创建字节输入流   fis = new FileInputStream("FileOutputStreamTest.java");   //创建字节输出流   fos = new FileOutputStream("newFile.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  {   if(fis != null)   {    fis.close();   }   if(fos != null)   {    fos.close();   }  } }}

           

给我老师的人工智能教程打call!http://blog.csdn.net/jiangjunshow

这里写图片描述

猜你喜欢

转载自blog.csdn.net/hffyyff/article/details/84195436
今日推荐