zoukankan      html  css  js  c++  java
  • IO流

     1 package day02.com.offcn.test;
     2 
     3 import java.io.*;
     4 
     5 /**
     6  * @author: CC
     7  * @date: 2019/9/8
     8  */
     9 public class IO {
    10     //字节流转字符流转高效流
    11     public static void main(String[] args) throws IOException {
    12         test3();
    13     }
    14     //打印流  最简单的输出文档
    15     public static void test3() throws IOException {
    16         PrintWriter printWriter = new PrintWriter(new FileWriter("D:/aa.txt"),true);
    17         printWriter.write("大所发生的");
    18         printWriter.close();
    19     }
    20     public static void test() throws IOException {
    21         FileInputStream fileInputStream = new FileInputStream("D:/aa.txt");
    22         FileOutputStream fileOutputStream = new FileOutputStream("D:/bb.txt");
    23 
    24         InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream);
    25         OutputStreamWriter outPutStreamWriter = new OutputStreamWriter(fileOutputStream);
    26 
    27         BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
    28         BufferedWriter bufferedWriter = new BufferedWriter(outPutStreamWriter);
    29 
    30         int len = 0;
    31         while ((len = bufferedReader.read())!= -1){
    32             bufferedWriter.write(len);
    33         }
    34 
    35         bufferedWriter.flush();
    36 
    37         bufferedReader.close();
    38         bufferedWriter.close();
    39     }
    40     //字节流转高效流
    41     public static void test2() throws IOException {
    42         FileInputStream fileInputStream = new FileInputStream("D:/aa.txt");
    43         FileOutputStream fileOutputStream = new FileOutputStream("D:/bb.txt");
    44 
    45         BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream);
    46         BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(fileOutputStream);
    47         int len = 0;
    48         while ((len = bufferedInputStream.read())!=-1){
    49             bufferedOutputStream.write(len);
    50         }
    51         bufferedOutputStream.flush();
    52 
    53         bufferedInputStream.close();
    54         bufferedOutputStream.close();
    55     }
    56     //字符流转高效流
    57     public static void test1() throws IOException {
    58         FileReader fileReader = new FileReader("D:/aa.txt");
    59         FileWriter fileWriter = new FileWriter("D:/bb.txt");
    60         BufferedReader bufferedReader = new BufferedReader(fileReader);
    61         BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
    62 
    63         String len ="";
    64         while ((len = bufferedReader.readLine())!= null){
    65             bufferedWriter.write(len);
    66         }
    67 
    68         bufferedWriter.flush();
    69 
    70         bufferedReader.close();
    71         bufferedWriter.close();
    72     }
    73 }
    我凝视这恒星,等待这那场风暴,我已经准备好了
  • 相关阅读:
    wireshark无法捕获无线网卡数据解决办法(failed to set hardware filter to promiscuous mode)
    用PHP检测用户是用手机(Mobile)还是电脑(PC)访问网站
    一次.net Socket UDP编程的10万客户端测试记录
    对象复制
    c#中volatile关键字的作用
    C#操作XML
    ASP.NET AJAX
    C#操作XMl2
    SQLServer 存储过程中不拼接SQL字符串实现多条件查询
    ASP.NET刷新页面的六种方法20081111 22:04asp.net页面刷新重是有问题,收藏几种方法挺有用的.
  • 原文地址:https://www.cnblogs.com/cheng5350/p/11503025.html
Copyright © 2011-2022 走看看