一.
内存操作流
之前的文件操作流是以文件的输入和输出为主的,文件操作流的输出位置是硬盘,但如果将输入输出的位置改变成了内存,就称为内存操作流,使用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 接口的类是可序列化的。没有实现此接口的类将不能使它们的任意状态被序列化或逆序列化。
三.反序列