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 接口的类是可序列化的。没有实现此接口的类将不能使它们的任意状态被序列化或逆序列化。

    三.反序列

  • 相关阅读:
    min25筛学习笔记
    【模板】回滚莫队&不删除莫队
    UOJ#188. 【UR #13】Sanrd
    LOJ#572. 「LibreOJ Round #11」Misaka Network 与求和
    Product
    Lcm
    点是否在三角形内的判断
    今天学会了 在Linux下,用GCC编译C语言程序,mark下
    让你沉迷的五种设计
    搞清楚了自发光特效的制作原理,3张图,3个步骤
  • 原文地址:https://www.cnblogs.com/qiangini/p/13443073.html
Copyright © 2011-2022 走看看