zoukankan      html  css  js  c++  java
  • java学习31天2020/8/5

    一.

    内存操作流

            之前的文件操作流是以文件的输入和输出为主的,文件操作流的输出位置是硬盘,但如果将输入输出的位置改变成了内存,就称为内存操作流,使用ByteArrayInputStream 完成内存的输入操作,而使用ByteArrayOutputStream完成内存的输出操作。

    import java.io.ByteArrayInputStream;
    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    public class ByteOutputStreamDemo {
        public static void main(String[] args)throws IOException {
            outin();
        }
        public static void outin()throws IOException{
            String info="hello java";
            InputStream input=new ByteArrayInputStream(info.getBytes());
            OutputStream output=new ByteArrayOutputStream();
            int temp=0;
            while((temp=input.read())!=-1) {
                output.write(Character.toUpperCase((char)temp));
            }
            String str=output.toString();
            input.close();
            output.close();
            System.out.println(str);
        }
    }
    

     序列

    import java. io. Serializable;
    public class Person implements Serializable{
             private String name;
             private int age;
             public String getName() {
                 return name;
             }
              public void setName (String name) {
                  this. name = name;
             }
              public int getAge() {
                  return age;
              }
              public void setAge (int age) {
                    this.age = age;
              }
              public String toString() {
                   return   "姓名: "+name+", 年龄: "+age;
              }
    }
    

     二.Serializable接口是启用其序列化功能的接口。实现java.io.Serializable 接口的类是可序列化的。没有实现此接口的类将不能使它们的任意状态被序列化或逆序列化。

    三.反序列

  • 相关阅读:
    Oracle VM VirtualBox安装centos8
    HTML5 离线缓存manifest
    ES6 Proxy函数和对象的增强
    ES6 Map数据结构
    ES6 Set和WeakSet
    ES6Symbol在对象中的应用
    ==,===,与ES6中is()的区别
    ES6对象操作
    ES6函数和数组补漏
    ES6箭头函数
  • 原文地址:https://www.cnblogs.com/qiangini/p/13443073.html
Copyright © 2011-2022 走看看