IO流(9)--字符流的三种拷贝
来源:互联网 发布:数控编程方法 编辑:程序博客网 时间:2024/06/07 03:02
字符流FileReader
public static void main(String[] args) throws IOException { FileReader fr=new FileReader("xxx.txt"); int b; while((b=fr.read())!=-1){ System.out.print((char)b); //因为是中文,所以要强制转换 } fr.close(); }
FileWriter
public static void main(String[] args) throws IOException { FileWriter fw=new FileWriter("yyy.txt"); fw.write("大家好,hahaha"); fw.write(97); //会写一个 a 在文件yyy.txt中 fw.close(); }
字符流的拷贝
public static void main(String[] args) throws IOException { FileReader fr=new FileReader("xxx.txt"); FileWriter fw=new FileWriter("yyy.txt"); int c; while((c=fr.read())!=-1){ fw.write(c); } fr.close(); fw.close(); //writer类中有一个2K的缓冲区,如果不关流,就会将内容写到缓冲区里 }
带有数组的拷贝
public static void main(String[] args) throws IOException { FileReader fr=new FileReader("xxx.txt"); FileWriter fw=new FileWriter("yyy.txt"); char[] arr=new char[1024]; int len; while((len=fr.read(arr))!=-1){ //将文件上的数据读取到字符数组中 fw.write(len); //将字符数组中的数据写到文件上 } fr.close(); fw.close(); }
带有缓冲区的字符流拷贝
public static void main(String[] args) throws IOException { BufferedReader br=new BufferedReader(new FileReader("xxx.txt")); BufferedWriter bw=new BufferedWriter(new FileWriter("zzz.txt")); int b; while((b=br.read())!=-1){ bw.write(b); } br.close(); bw.close(); }
阅读全文
0 0
- IO流(9)--字符流的三种拷贝
- IO(三)字符流
- IO流文件的拷贝
- Java中,IO流(三):字符流的过滤器
- java io 学习之三 字符流的缓冲区
- 史上最全的IO框架三(字符流)
- IO流对文件的拷贝(字节流与字符流)
- IO流(三)字符流
- 字符流---IO学习笔记(三)
- 三种IO库实现文件的拷贝
- IO流(拷贝文本文件)
- IO流(拷贝图片)
- IO流--拷贝文本文件
- IO流--拷贝图片
- io流拷贝文本文件
- IO流拷贝图片
- io流-文件拷贝
- io流 拷贝
- 端口
- Good url for my CV
- Leetcode:714. Best Time to Buy and Sell Stock with Transaction Fee
- [BZOJ1559]-[JSOI2009]密码-补全AC自动机+状压dp
- js基础
- IO流(9)--字符流的三种拷贝
- 再谈Linux内核中的RCU机制
- Java Web 知识总结
- [LeetCode] 154. Find Minimum in Rotated Sorted Array II
- Keras with R (MLP)
- ###Springmvc封装复杂表单数据:表单提交多个实体类的参数【对象类型参数,自动封装】name属性值不能重复。和实体类属性名一致
- 个人学习笔记02-DoTween插件简单运用
- Android项目中加入弹幕功能
- 有缘与你第一次相见!