最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

數(shù)據(jù)流的代碼

2020-04-03 22:14 作者:小垃圾kiki  | 我要投稿
package cn.jd.io;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
/*
?* 數(shù)據(jù)流:
?* 1先寫出后讀取
?* 2讀取的順序和寫出保持一致
?*/
public class DataTest {
?? ?public static void main(String[] args) throws IOException {
?? ??? ?//字節(jié)數(shù)組流
?? ??? ?ByteArrayOutputStream? baos=new ByteArrayOutputStream();
?? ??? ? //先寫出再讀取,因?yàn)槟悴粚懩阕x什么內(nèi)容,所以你先寫一個(gè)內(nèi)容讓人家讀
?? ??? ?DataOutputStream dos=new DataOutputStream(new BufferedOutputStream(baos));
?? ??? ?//接下來就是怎么寫入到字節(jié)數(shù)組里面了??? 操作數(shù)據(jù)類型+數(shù)據(jù)
?? ??? ?dos.writeUTF("我太難了");
?? ??? ?dos.writeInt(18);
?? ??? ?dos.writeBoolean(false);
?? ??? ?dos.flush();
?? ??? ?byte[]? datas=baos.toByteArray();?? //將字節(jié)流轉(zhuǎn)為字節(jié)數(shù)組
?? ??? ?
?? ??? ?//讀取
?? ??? ?DataInputStream dis=new DataInputStream(new BufferedInputStream(new ByteArrayInputStream(datas)));
?? ??? ?//接下來就是從程序里面讀取內(nèi)容,順序要和寫出的一致
?? ??? ? String msg=dis.readUTF();
?? ??? ? int age=dis.readInt();
?? ??? ? boolean flag=dis.readBoolean();
?? ??? ? System.out.println(msg);
?? ??? ?
?? ?}
}

數(shù)據(jù)流的代碼的評論 (共 條)

分享到微博請遵守國家法律
沁水县| 通山县| 神池县| 永胜县| 武隆县| 吉水县| 且末县| 南丰县| 梧州市| 友谊县| 广安市| 白山市| 安庆市| 上饶县| 广水市| 阿拉善左旗| 棋牌| 酉阳| 堆龙德庆县| 城固县| 应城市| 榆中县| 额济纳旗| 越西县| 信丰县| 毕节市| 嵩明县| 汤原县| 沿河| 淮北市| 万年县| 仙居县| 仪陇县| 沁水县| 建昌县| 黄石市| 措勤县| 北海市| 恩平市| 比如县| 澄江县|