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四种访问权限,并且这四 ...
随机推荐
- 线段树详解 (原理,实现与应用)(转载自:http://blog.csdn.net/zearot/article/details/48299459)
原文地址:http://blog.csdn.net/zearot/article/details/48299459(如有侵权,请联系博主,立即删除.) 线段树详解 By 岩之痕 目录: 一:综述 ...
- ipv4保留地址
曾经以为保留地址下面三类.原来使用中还有很多的. A类 10.0.0.0--10.255.255.255 B类 172.16.0.0--172.31.255.255 C类 192.168.0.0--1 ...
- 部署web前端的react项目到linux服务器
部署web前端的react项目到linux服务器 项目的目录结构 ``` ├─dlls #dlls编译后的问题 ├─doc #帮助文件入口 │ ├─src │ ├─apps #各个功能模块放在这里 │ ...
- C语言学习笔记9-指针
1.指针基础 NULL为预处理器变量,是从C继承下来的,该变量在cstdlib头文件中定义 2.指针函数与函数指针 3.指针数组与数组指针 4.
- 在AspNetCore3.0中使用Autofac
1. 引入Nuget包 Autofac Autofac.Extensions.DependencyInjection 2. 修改Program.cs 将默认ServiceProviderFactory ...
- Multiline f-strings
多行字符串使用fstring需要注意每行都要加fstring >>> name = "Eric" >>> profession = " ...
- QT 自定义消息
#define TEST_EVENT QEvent::User + 100 class CVxActuatorMain : public QMainWindow { protected: ...
- Flutter移动电商实战 --(29)列表页_商品列表数据模型建立
简历数据模型 json生成dart类的网站: https://javiercbk.github.io/json_to_dart/ json数据 {"code":"0&qu ...
- treeview所有节点递归解法及注意!!!!!!!!!!!!!!!!!
好吧 我把所有之前写的都删了,只为这一句话“所有变量切记小心在递归函数内部初始化”,包括:布尔,变量i,等等.至于为什么....递归就是调用自己,你初始化以后的变量,等再次调用的时候又回来了 bool ...
- Google Directions API 中路线编码解析
public List<Location> GetGeoPoints(string encoded) { List<Location> poly = new List<L ...