java中讲讲DataInputStream的用法,举例?
[学习笔记]
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 later
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
java中讲讲DataInputStream的用法,举例?的更多相关文章
- java中讲讲PrintWriter的用法,举例?
[学习笔记] 1.2 PrintWriter的用法 PrintWriter和PrintStream类似,只不过PrintStream是针对字节流的,而PrintWriter是针对字符流的. 例:1.2 ...
- java中讲讲PrintStream的用法,举例?
[学习笔记] 1.2 PrintStream的用法 从学java第一天,我们就经常用到System.out.println(),实际上查阅文档可知,System.out就是Sun 编的一个Prin ...
- Java中的Socket的用法
Java中的Socket的用法 Java中的Socket分为普通的Socket和NioSocket. 普通Socket的用法 Java中的 ...
- Java中Date各种相关用法
Java中Date各种相关用法(一) 1.计算某一月份的最大天数 Java代码 Calendar time=Calendar.getInstance(); time.clear(); time.set ...
- JAVA中enum的常见用法
JAVA中enum的常见用法包括:定义并添加方法.switch.遍历.EnumSet.EnumMap 1.定义enum并添加或覆盖方法 public Interface Behaviour{ void ...
- 巨人大哥谈Java中的Synchronized关键字用法
巨人大哥谈Java中的Synchronized关键字用法 认识synchronized 对于写多线程程序的人来说,经常碰到的就是并发问题,对于容易出现并发问题的地方价格synchronized基本上就 ...
- Java中Class类及用法
Java中Class类及用法 Java程序在运行时,Java运行时系统一直对所有的对象进行所谓的运行时类型标识,即所谓的RTTI.这项信息纪录了每个对象所属的类.虚拟机通常使用运行时类型信息选准正确方 ...
- JAVA中mark()和reset()用法
根据JAVA官方文档的描述,mark(int readlimit)方法表示,标记当前位置,并保证在mark以后最多可以读取readlimit字节数据,mark标记仍有效.如果在mark后读取超过rea ...
- java中class,public的用法
java中class,public的用法 一.Java访问权限饰词(access specifiers) Java有public.protect.friendly.private四种访问权限,并且这四 ...
随机推荐
- CF796C Bank Hacking 细节
思路十分简单,答案只有 3 种可能,但是有一些细节需要额外注意一下. code: #include <bits/stdc++.h> #define N 300002 #define set ...
- [Luogu] 贪婪大陆
https://www.luogu.org/problemnew/show/P2184 区间修改时只需修改区间端点的numl或numr值 区间查询x-y只需用1-y的numr - 1-(x - 1)的 ...
- Cogs 58. 延绵的山峰(st表)
延绵的山峰 ★★☆ 输入文件:climb.in 输出文件:climb.out 简单对比 时间限制:1 s 内存限制:512 MB 问题描述 有一座延绵不断.跌宕起伏的山,最低处海拔为0,最高处海拔不超 ...
- speech-to-text-wavenet
docker pull buriburisuri/speech-to-text-wavenet docker run -it buriburisuri/speech-to-text-wavenet p ...
- 协议基础:SMTP:使用Telnet学习SMTP协议
协议基础:SMTP:使用Telnet学习SMTP协议 2018-07-30 20:05:50 liumiaocn 阅读数 7479更多 分类专栏: 工具 Unix/Linux 版权声明:本文为博主 ...
- League of Leesins
C - League of Leesins 首先找到每一串数字的头和尾两个数字,这两个数字有一个特点,就是它们在输入数据的时候都只会出现一次.我们在输出的时候用头和尾做第一数都可以. 然后第二个数只会 ...
- POJ2689
题目 POJ2689 Prime Distance 原题传送门 主要思路 刚看到这题,心想:不就筛个 \(\left[2,U\right]\) 的质数表出来就可以了吗?一看数据范围: \(1<= ...
- Apache Flink - 基本API概念
Flink程序是实现分布式集合转换的常规程序.集合最初是从源创建的.通过接收器(slink)返回结果,接收器可以将数据写到某个文件或stdout.Flink可以在各种环境(context)中运行,本地 ...
- 关系型数据库的树形结构查询(Oracle、Postgres)
Oracle : start with… connect by 的用法.语法:select * from table [where 条件1] connect by[条件2] start with[条件 ...
- Multiline f-strings
多行字符串使用fstring需要注意每行都要加fstring >>> name = "Eric" >>> profession = " ...