首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >java中讲讲DataInputStream的用法,举例?

java中讲讲DataInputStream的用法,举例?

作者头像
马克java社区
修改2021-05-07 10:20:41
修改2021-05-07 10:20:41
6230
举报
文章被收录于专栏:java大数据java大数据

2.4 DataInputStream的用法 

马 克-to-win:DataInputStream顾名思义:就是专门用来读各种各样的数据的,比如(int,char,long等),一定要注意 DataOutputStream 与DataInputStream配合使用,而且二者读写的顺序要一样,可以参照下面的例子。

例:2.4.1

import java.io.*;

public class TestMark_to_win {

    /* when run this program, no need any data.dat file, because it can generate

the file.anyway,this file can not be recognized by humanbeing

*/

    public static void main(String[] args) throws IOException {

        FileOutputStream fos = new FileOutputStream("c:/data.txt");

        DataOutputStream dos = new DataOutputStream(fos);

        dos.writeInt(345);

        dos.writeDouble(4.54);

        dos.writeUTF("我们");

        dos.close();

        FileInputStream fis = new FileInputStream("c:/data.txt");

        DataInputStream dis = new DataInputStream(fis);

        /*1) a data output stream to write data that can late

be read by a data input stream. 2)note the sequence.first write what,

then read what. if you comment out the following statment,the result

is not correct, because the sequence is chaotic.I tried. 3) readInt()

Returns: the next four bytes of this input stream, interpreted as an

int. */

更多请见:https://blog.csdn.net/qq_44594249/article/details/99294564

本文系转载,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文系转载前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档