Java,IO之FileOutputStream和FileWriter写入文件(疯狂java讲义)
2012-07-14 14:28
369 查看
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(); } } } }
相关文章推荐
- 初学Java,IO之使用FileOutputStream和FileWriter写入文件(四十二)
- 初学Java,IO之使用FileOutputStream和FileWriter写入文件(四十二)
- Java基础之IO流,创建文件并写入内容与IO异常的标准处理方法
- [测试]java IO写入文件效率——几种方法比较
- java的io操作(将字符串写入到txt文件中)
- [学习笔记]Java文件IO操作------实现对文件的读取与写入
- Java IO 读取/写入文件 中文乱码困难解决代码
- Java在硬盘上创建一个文件并写入一些文字数据FileWriter
- Java IO中的FileReader 和 FileWriter读写文件,和创建多级文件夹
- Java IO 之 FileReader FileWriter 实现字符文件的复制(处理FileWriter新建文件失败的问题)
- 黑马程序员-JAVA高级视频_IO输入与输出-20天-4(File文件写入)
- Java IO操作之文件读取与写入 无乱码FileOutputStream FileInputStream使用-IO写utf-8乱码问题
- Java IO深入理解读写文件(FileInputStream、FileOutputStream、FileReader、FileWriter、RandomAccessFile)
- java-IO操作——使用FileWriter和FileReader来操作文件
- 多次创建object 写入对象文件中.java.io.StreamCorruptedException: invalid type code: AC解决办法
- Java,IO之FileInputStream和FileReader读取文件(疯狂java讲义)
- java的io操作(将字符串写入到txt文件中)
- java 使用IO字节流将一句话写入文件
- java的io操作(将字符串写入到txt文件中)
- java IO写入文件(含键盘输入)