在千峰“逆战班”学习的第31天
今天的学习内容是IO框架中的流,字节流的抽象父类OutputStream和InputStream,它们的子类字节节点流 FileOutputStream和FileInputStream以及字节过滤流中的缓冲流和对象流
中国加油!武汉加油!千峰加油!我自己加油!!
作业:
3.输入 字节 节点
4.
1)int 读取下一个字节
2)每次读取的有效字节数 存储读取数据的数组
3) 存储的数据在数组中的起始下标 读取的字节数
5.AB
6.1)创建文件 覆盖
2)输出的数据叠加 会
7.抛出IOException异常
8.
public class Test {
public static void main(String[] args){
FileOutputStream fos = null;
FileInputStream fis =null;
try {
fos = new FileOutputStream("test.txt");
String s = "Hello World";
fos.write(s.getBytes());
fis = new FileInputStream("test.txt");
while(true){
int n = fis.read();
if(n == -1){
break;
}
System.out.print((char)n);
}
} catch (Exception e) {
e.printStackTrace();
}finally{
try {
fos.close();
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
运行结果:
13.Serializable transient
15.PrintWrite的print(Object obj)方法是打印一个对象。 由String.valueOf(Object)方法生成的字符串根据平台的默认字符编码转换为字节,这些字节的write(int)的方式编写。
ObjectOutputStream中的writeObject(Object obj)方法是打印一个对象。 由String.valueOf(Object)方法生成的字符串根据平台的默认字符编码转换为字节,这些字节的write(int)的方式编写。必须实现序列化。
16.B