JAVAIO流

//            【I/O】input output :Java对系统中的文件系统的支持
//        【i/o体系】:
//        1.处理单位:字节流,字符流
//       2.处理流向:输入流,输出流
//        3.处理功能:节点流,处理流
//          字节流:适合处理音频,视频,图片  读取汉字 分成三个数字
//        字符流:通常适合用于处理汉字多的文本文件 读取汉字 分成一个数字
//        write 不可以写空 append可以为空
//    字节流的读取:把A文件的内容读取到B文件
FileInputStream input=null;

FileOutputStream  output=null;
input=new FileInputStream(path);  //文件找不到异常 FileNotFoundException
output=new FileOutputStream(path); 覆盖  

output=new FileOutputStream(path,true); 追加

int b=0;
while ((b =input.read())!=-1){//read I0异常  read 返回值为int -1代表没有值 
    System.out.println((char) b);//读取汉字会乱码 覆盖
    output.write(b);
}

         关闭输入流 input.close();
         关闭输出流 output.close();
           
// 字节流的读取,字符串写入b文件
        String s="hehehhe";    
        byte[] bs=s.getBytes();
        output.write(bs);

//    字节流的读取:把A文件的内容读取到B文件
        FileInputStream input = null;

        FileOutputStream output = null;
//        读A文件



            input = new FileInputStream(path);
            output = new FileOutputStream(path);
//            output=new FileOutputStream(path,true);//追加

            int b = 0;
            while ((b = input.read()) != -1) {//read I0异常 -1代表没有值
                System.out.println((char) b);//读取汉字会乱码 覆盖
                output.write(b);


//            关闭输入流  input.close();
//            关闭输出流 output.close();
           
            字符流
  public static void example5() throws IOException {

        FileReader input = null;
        FileWriter output = null;
        input = new FileReader("F:\\idea\\IntelliJ IDEA 2020.1.1\\Project\\src\\com\\hzh\\javase\\day019\\a1.txt");
        output = new FileWriter("F:\\idea\\IntelliJ IDEA 2020.1.1\\Project\\src\\com\\hzh\\javase\\day019\\b5.txt");

        int b = 0;

        while (b != -1) {
            b = input.read();
            System.out.println((char) b);// output.write(b);
//           System.out.println(b);
            //使用字符流汉字不乱码

        }
        input.close();
        output.close();
    }

    // 字符流的缓冲流读取
    public static void exampl6() throws IOException {
        BufferedReader input = null;
        BufferedWriter output = null;
        input = new BufferedReader(new FileReader(path) {
        });
        output = new BufferedWriter(new FileWriter(path));

        String str = null;
//        input.readLine(); //跳过第一行
        while ((str = input.readLine()) != null) {
            System.out.println(str);
            output.write(str);
            output.newLine();//添加换行
//            output.write(null);报错 
//append不会叠加 
            output.append(null);   //显示"null"字符串
            output.append("\n");
        }
        input.close();
out.plush();//刷新
        output.close();
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值