zoukankan      html  css  js  c++  java
  • 021.15 IO流 其他流

    IO包中的其他类
    操作基本数据类型:DataInputStream与DataOutputStream
    操作字节数组:ByteArrayInputStream与ByteArrayOutputStream
    操作字符数组:CharArrayReader与CharArrayWriter
    操作字符串:StringReader与StringWriter

    ####DataInputStream与DataOutputStream
    public static void main(String[] args) throws IOException
    {
        writeFile();
        readFile();
    }
    
    
    private static void writeFile() throws IOException
    {
        FileOutputStream fos = new FileOutputStream("myfile\data.txt");
        DataOutputStream dos = new DataOutputStream(fos);
        
        dos.writeBoolean(true);
        
        dos.close();
    }
    
    private static void readFile() throws IOException
    {
        FileInputStream fis = new FileInputStream("myfile\data.txt");
        DataInputStream dis = new DataInputStream(fis);
        
        boolean b;
        b = dis.readBoolean();
        System.out.println(b);
        
        dis.close();
    }
    
    
    #####ByteArrayInputStream与ByteArrayOutputStream
    public static void main(String[] args)
    {
        ByteArrayInputStream bis = new ByteArrayInputStream("abcdef".getBytes());
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        
        int b;
        while((b = bis.read())!=-1){
            bos.write(b);
        }
        System.out.println(bos.toString());
    }
  • 相关阅读:
    求一个数字各个位的数字之和
    二进制和十进制的转换 分别用python和js实现
    pymysql 获取插入数据的主键id
    js03.事件
    02.js运算符
    jsonpath
    01.js控制台
    2.命令补充
    hashmap
    正则表达式的补充
  • 原文地址:https://www.cnblogs.com/-nbloser/p/9651111.html
Copyright © 2011-2022 走看看