zoukankan      html  css  js  c++  java
  • java学习27天2020/8/1

    一.

    输入流代表从外部流入计算机的数据序列,输出流代表计算机流入外部的数据序列

    对流的操作扥为字节流和字符流

    字节流对二进制文件,图片及影响文件的操作;字符流针对文本文件;

    字节流

    输出字节流OutputStream,是所有输出字节流的父类,并且是一个抽象类;

    常用的几种方法

    关闭流:public void close() throws IOException

    写一组数据:public void write(byte[] b) throws IOException.
    写一个数据: public void write(int b) throws IOException。 但是要想将Outputream实例化,且进行文件操作,就要使用FileOutputStream 子类。
    构造: public FileOutputStream(File file) throws FileNotFoundException.

    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.OutputStream;
    public class FileOutStreamDemo {
        public static void main(String[] args)throws IOException {
            out();
        }
        public static void out()throws IOException{
            OutputStream out=new FileOutputStream("D:/Hello.txt");
            String info="Hello Java!";
            byte[] buf=info.getBytes();
            out.write(buf);
            out.close();
        }
    }
    

    重新运行会将源文件的内容覆盖

    在文件中追加内容   public FileOutputStream(File file,boolean append)throws FileNotFoundException;

    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.OutputStream;
    public class FileOutStreamDemo {
        public static void main(String[] args)throws IOException {
            out();
        }
        public static void out(){
            OutputStream out=null;
            try {
               out=new FileOutputStream("D:/Hello.txt",true);
               String info="Hello PHP!";
               byte[] buf=info.getBytes();
               out.write(buf);
            }catch(IOException e) {
                e.printStackTrace();
            }finally {
                try {
                    if(out!=null) out.close();
                }catch(IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    

     

     二.字节数组不熟悉

    三inputstream

  • 相关阅读:
    Python-PyQt5-图形可视化界面(5)--打开文件或文件夹--QFileDialog
    python opencv图片拼接源码
    python numpy库矩阵运算的功能
    stm32定时器/定时器中断/PWM输出/输入捕获
    STM32 串口/中断
    STM32F4 IO
    STM32F4 时钟树概述
    MDK5新建工程/MDK5 使用技巧/STM32F4 在线调试
    使用 LocalDate 过滤掉工作日
    斐波拉契数列(Lambda表达式)
  • 原文地址:https://www.cnblogs.com/qiangini/p/13416570.html
Copyright © 2011-2022 走看看