首页 > 编程语言 > 详细

java:I/O 字节流和字符流

时间:2014-05-26 01:00:23      阅读:364      评论:0      收藏:0      [点我收藏+]

字节流

InputStream和OutputStream的子类:FileInputStream 和 FileOutputStream

方法:

int read(byte[] b,int off,int len);

void write(byte[] b,int off,int len);

字符流

Reader和Writer的子类:FileReader 和 FileWriter

方法:

int read(char[] b,int off,int len);

void write(char[] b,int off,int len);

 使用区别仅在于:类和数组类型

bubuko.com,布布扣
import java.io.*;
class Test
{
    public static void main(String args[]){
        FileReader fr =null;
        FileWriter fw =null;

        try{
            fr = new FileReader("e://d/from.txt");
            fw = new FileWriter("e://d/to.txt");
            char [] arr =new char[100];
            while(true){
                int temp =fr.read(arr,0,100);
                if(temp == -1){
                break;
                }
                fw.write(arr,0,temp);
            }
        }catch(Exception e){
            System.out.println(e);
        }
        finally{
            try{
                fr.close();
                fw.close();
            }catch(Exception e){
                System.out.println(e);
            }
        }
    }
}
bubuko.com,布布扣

 

java:I/O 字节流和字符流,布布扣,bubuko.com

java:I/O 字节流和字符流

原文:http://www.cnblogs.com/tinyphp/p/3749865.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!