首页 > 移动平台 > 详细

android开发字符流

时间:2016-03-17 10:58:28      阅读:217      评论:0      收藏:0      [点我收藏+]

字符流:读写文件时,以字符为基础

 

字节输入流 :reader抽象类 常用子类:FileReader

用法:int read(char 【】c,int off,int len)

 

字节输出流:writer抽象类 常用子类:FileWriter

用法:void writer(char 【】 c ,int off,int len)

 

demo:

package test;
import java.io.*;
public class TestChar {
    public static void main(String args []) {
        FileReader fileReader = null;
        FileWriter fileWriter = null;
        char c [] = new char[100];
        try {
            fileReader = new FileReader("/Users/ningyu/Desktop/from.txt");
            fileWriter = new FileWriter("/Users/ningyu/Desktop/to.txt");
            
            while(true){
                int temp = fileReader.read(c, 0, c.length);
                
                if (temp == -1) {
                    break;
                }
                
                fileWriter.write(c, 0, c.length);
            }
            
//            System.out.println(temp);
            
            for(int i = 0;i < c.length; i++){
                System.out.println(c[i]);
            }
            
            
            
        } catch (Exception e) {
            System.out.println(e);
        }finally {
            try {
                fileReader.close();
                fileWriter.close();
            } catch (Exception e2) {
                System.out.println(e2);
            }
        }
    }
}

android开发字符流

原文:http://www.cnblogs.com/ningxiaoge/p/5286388.html

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