zoukankan      html  css  js  c++  java
  • 【每日日报】第三十三天---文件操作(缓冲流)

    1 今天继续看书

    缓冲流读文件

     1 package File;
     2 import java.io.BufferedReader;
     3 import java.io.FileInputStream;
     4 import java.io.IOException;
     5 import java.io.InputStreamReader;
     6 
     7 public class BufferedReaderDemo {
     8     public static void main(String[] args)throws IOException{
     9         read();
    10     }
    11     public static void read() throws IOException{
    12         BufferedReader read=new BufferedReader (new InputStreamReader(new FileInputStream("D:/Hello.txt")));
    13         String line=null;
    14         while((line=read.readLine())!=null){
    15             System.out.println(line);
    16         }
    17         read.close();
    18     }
    19 
    20 }

    缓冲流写文件

     1 package File;
     2 import java.io.BufferedWriter;
     3 import java.io.FileOutputStream;
     4 import java.io.IOException;
     5 import java.io.OutputStreamWriter;
     6 
     7 public class BufferedWriterDemo {
     8     public static void main(String[] args)throws IOException{
     9         write();
    10     }
    11     public static void write()throws IOException{
    12         BufferedWriter w=new BufferedWriter(new OutputStreamWriter(new FileOutputStream("D:/Hello.txt")));
    13         w.write("Hello");
    14         w.write("Java");
    15         w.close();
    16     }
    17 
    18 }

    使用BufferedInputStream和BufferedOutputStream读写图片

     1 package File;
     2 import java.io.BufferedInputStream;
     3 import java.io.BufferedOutputStream;
     4 import java.io.FileInputStream;
     5 import java.io.FileOutputStream;
     6 import java.io.IOException;
     7 
     8 public class BufferedInputOutput {
     9     public static void main(String[] args)throws IOException{
    10         outIn();
    11     }
    12     public static void outIn()throws IOException{
    13         BufferedInputStream in=new BufferedInputStream(new FileInputStream("C:\Users\linmob\Pictures\ps\a.png"));
    14         BufferedOutputStream out=new BufferedOutputStream(new FileOutputStream("C:\Users\linmob\Pictures\ps\a2.png"));
    15         byte[] buf=new byte[1024];
    16         int len=-1;
    17         while((len=in.read(buf))!=-1){
    18             out.write(buf,0,len);
    19         }
    20         out.close();
    21         in.close();
    22     }
    23 }

    2 没有其他问题 

    3 明天继续看书

  • 相关阅读:
    mysql 严格模式 Strict Mode
    PHP中NULL和‘'的区别
    nginx 出现413 Request Entity Too Large问题的解决方法
    mysql 转换NULL数据方法
    mysql大小写敏感配置
    mysql导入大批量数据出现MySQL server has gone away的解决方法
    mysql函数concat与group_concat使用说明
    Linux下aMule安装教程
    四、YOLO-V1原理与实现(you only look once)
    tf.cast(ndarray,dtype)
  • 原文地址:https://www.cnblogs.com/linmob/p/13455336.html
Copyright © 2011-2022 走看看