3.(流的分类)对于FileInputStream来说,从方向上来分,它是输入流,从数据单位上分,它是字节流,从功能上分,它是节点流。
4.read方法:
无参的read()方法返回的int类型,是表示数据下一个字节的字节码,如果已经到达流的最后面了,那就返回-1.
read(byte [] bs)方法返回值表示内存空间,参数表示希望读取的字节数
int read(byte b[], int off, int len)方法的返回值就是我们设定的要读取的字节码的长度,off处开始到流数据末端len的字节数了。
5.B
7.
public class Test7 {
public static void main(String[] args) throws FileNotFoundException {
FileInputStream fin=new FileInputStream("Files\\test.txt");
try {
System.out.println(fin.read());
} catch (IOException e) {
e.printStackTrace();
}
}
}
8.
public static void main(String[] args) throws IOException {
FileOutputStream fos=new FileOutputStream("Files\\test.txt");
String str="helloworld";
fos.write(str.getBytes());
FileInputStream fin=new FileInputStream("Files\\test.txt");
byte[] bytes=new byte[10];
try {
fin.read(bytes);
} catch (IOException e) {
e.printStackTrace();
}finally {
fin.close();
}
for (int i = 0; i < bytes.length; i++) {
System.out.print((char)bytes[i]);
}
}
}
输出参考:
helloworld
13.I.为了让对象能够被序列化,要求其实现Serializable接口;
II.为了让该对象某个属性不参与序列化,应当使用transient修饰符
16.B