DataInputStream(InputStream instream)
The constructor requires you to pass in an input stream. This instance
might be a file input stream (because FileInputStream extends Input-
Stream), an input stream from a socket, or any other kind of input stream.
When the instance of DataInputStream is called on to deliver data, it will
make some number of read() calls on instream, process the bytes, and
return an appropriate value.
The constructor requires you to pass in an input stream. This instance
might be a file input stream (because FileInputStream extends Input-
Stream), an input stream from a socket, or any other kind of input stream.
When the instance of DataInputStream is called on to deliver data, it will
make some number of read() calls on instream, process the bytes, and
return an appropriate value.
解决方案 »
- java for循环改为递归(有难度)
- 请教一个SQL
- 继承的一点小问题,如果同时继承两个基类??
- 老师布置了一道作业(英文的),不会做啊,高手们能指点一下吗?谢谢
- 我用 bufferedwritter 写入到文件,可是用UNTRAEDIT打开这个生成的文件时,总是提示是否要convert到DOA format
- 我用appletviewer运行,为何提示未初始化程序
- 真诚求教!-高手看看这个java恢复SQL数据库的一个小小问题(解决给200分)
- 高手指教
- 大家都用哪些IDE开发?
- 为什么标签面板很小,怎么样叫标签面板大大的,有线等待?
- 我编的applet若想上传到个人主页空间上去,只要传.class和.html两个文件就够了吗
- 有关执行存储过程返回值的问题
1. try {
2. // Construct the chain
3. FileInputStream fis = new FileInputStream(“fname”);
4. DataInputStream dis = new DataInputStream(fis);
5.
6. // Read
7. double d = dis.readDouble();
8. int i = dis.readInt();
9. String s = dis.readUTF();
10.
11. // Close the chain
12. dis.close(); // Close dis first, because it
13. fis.close(); // was created last
14. }
15. catch (IOException e) { }
the next four bytes represent an int, and the next who-knows-how-many
bytes represent a UTF string. This means that the code that originally created the file must have been writing a double, an int, and a UTF string.
使用嵌套是为了得到更多流处理方法。
的确,FileOutputStream能够把内容写到文件中去,但它没有缓冲机制来提高效率,用BufferedOutputStream嵌套一下就能搞定了。
而你如果希望能够直接写基本类型的数据而不是单个字节的数据的话,就可以再用DataOutputStream包装一下,它提供writeBoolean、writeInt(int v) 等特有的方法。
因此,是否使用嵌套,看你的需要。
对于
3. FileInputStream fis = new FileInputStream(“fname”);
4. DataInputStream dis = new DataInputStream(fis);因为你可能要操作int 或是string 而不是bytes 所以你需要FilterOutputStream ,所以你需要流嵌套
而且没有缓冲,所以就套上了其他的输出流,
以便得到一些FileInputStream没有的write什么什么方法!是这样吧!