【每日日报】第三十二天---DataOutputStream写文件
1 今天继续看书
DataOutputStream写文件
1 package File;
2 import java.io.IOException;
3 import java.io.FileOutputStream;
4 import java.io.DataOutputStream;
5 import java.io.OutputStream;
6
7 public class DataOutputStreamDemo {
8 public static void main(String[] args)throws IOException{
9 write();
10 }
11 public static void write()throws IOException{
12 OutputStream os=new FileOutputStream("D:/Hello.txt");
13 DataOutputStream dos=new DataOutputStream(os);
14 dos.writeInt(123);
15 dos.writeBoolean(true);
16 dos.writeByte(34);
17 dos.writeBytes("Hello");
18 dos.writeChar(58);
19 dos.writeChars("java");
20 dos.writeDouble(20.0);
21 dos.writeFloat(20f);
22 dos.writeShort(31);
23 dos.writeUTF("C++");
24 dos.writeLong(13L);
25 dos.flush();
26 dos.close();
27 }
28
29 }
DataInputStream读数据
1 package File;
2 import java.io.DataInputStream;
3 import java.io.FileInputStream;
4 import java.io.IOException;
5 import java.io.InputStream;
6
7 public class DataInputStreamDemo {
8 public static void main(String[] args)throws IOException{
9 read();
10 }
11 public static void read()throws IOException{
12 InputStream in =new FileInputStream("D:/Hello.txt");
13 DataInputStream dis =new DataInputStream(in);
14 int a=dis.readInt();
15 System.out.println(a);
16 System.out.println(dis.readBoolean());
17 System.out.println(dis.readByte());
18 System.out.println(dis.readChar());
19 System.out.println(dis.readDouble());
20 System.out.println(dis.readFloat());
21 System.out.println(dis.readFloat());
22 System.out.println(dis.readShort());
23 System.out.println(dis.readLong());
24 dis.close();
25
26 }
27
28 }
内存操作流
1 package File;
2 import java.io.IOException;
3 import java.io.InputStream;
4 import java.io.OutputStream;
5 import java.io.ByteArrayInputStream;
6 import java.io.ByteArrayOutputStream;
7
8 public class ByteOutputStreamDemo {
9 public static void main(String[] args)throws IOException{
10 outin();
11 }
12 public static void outin()throws IOException{
13 String info ="hello Java";
14 InputStream input=new ByteArrayInputStream(info.getBytes());
15 OutputStream output=new ByteArrayOutputStream();
16 int temp=0;
17 while((temp=input.read())!=-1){
18 output.write(Character.toUpperCase((char)temp));
19 }
20 String str =output.toString();
21 input.close();
22 output.close();
23 System.out.println(str);
24 }
25
26 }
2 当用DataOutputStream写文件时,写出的文件会出现乱码
3 明天继续看书
【每日日报】第三十二天---DataOutputStream写文件的更多相关文章
- 分享一个CQRS/ES架构中基于写文件的EventStore的设计思路
最近打算用C#实现一个基于文件的EventStore. 什么是EventStore 关于什么是EventStore,如果还不清楚的朋友可以去了解下CQRS/Event Sourcing这种架构,我博客 ...
- Node.js写文件的三种方法
Node.js写文件的三种方式: 1.通过管道流写文件 采用管道传输二进制流,可以实现自动管理流,可写流不必当心可读流流的过快而崩溃,适合大小文件传输(推荐) var readStream = fs. ...
- iOS持续写文件到本地
NSString *tempSavePath = [NSString stringWithFormat:@"%@/Documents",kDocumentPath]; NSFile ...
- PHP写文件函数
/** * 写文件函数 * * @param string $filename 文件名 * @param string $text 要写入的文本字符串 * @param string $openmod ...
- node基础07:写文件
1.writeFile //server.js var http = require("http"); var writefile = require("./writef ...
- java写文件
randomAccessFile.close(); } e.printStack ...
- python 写文件,utf-8问题
写文件报数据. 同样的编码. 含中文字段的输出文件 编码为utf-8 无中文的却是asc import codecstxt = u”qwer”file=codecs.open(“test”,”w”,” ...
- Java基础之写文件——将素数写入文件中(PrimesToFile)
控制台程序,计算素数.创建文件路径.写文件. import static java.lang.Math.ceil; import static java.lang.Math.sqrt; import ...
- IAR MSP430如何生成烧写文件
IAR生成430烧写方法有2种, 第一种是:将工程的debug模式切换成release模式,看图片操作. 那个.d43文件就是仿真调试模式的文件. 这里的test.txt文件就是烧写文件了,不要 ...
随机推荐
- Tableau学习Step5一表计算、详细级别表达式、动作、外接python
Tableau学习Step5一表计算.详细级别表达式.动作.外接python 本文首发于博客冰山一树Sankey,去博客浏览效果更好. ) Tableau学习Step4一数据解释.异常值监测.参数使用 ...
- vue--按需加载的3种方式(解决网页首次加载速度慢的问题)
一.vue的异步组件加载 使用异步组件加载,打包的时候会将每个组件分开打包到不同的js文件中: {path: '/index', name: 'index', meta:{ title:'首页', r ...
- WPF优秀组件推荐之Stylet(二)
上一篇文章介绍了Stylet的一些基本功能,本篇将介绍一些深入一点的功能. 依赖注入 在Bootstrapper 类中注入需要的对象: public class Bootstrapper : Boot ...
- LeetCode-022-括号生成
括号生成 题目描述:数字 n 代表生成括号的对数,请你设计一个函数,用于能够生成所有可能的并且 有效的 括号组合. 示例说明请见LeetCode官网. 来源:力扣(LeetCode) 链接:https ...
- 关于 vue2.x 的 $attrs 和 $listeners
$attrs $attrs 用于多层次组件传递参数(组件标签的attribute,class和style除外),爷爷辈组件向孙子辈组件传递参数(注:参数不能被父辈prop识别,一旦被父辈prop识别且 ...
- [csi]浅聊ceph-csi组件
描述 ceph-csi扩展各种存储类型的卷的管理能力,实现第三方存储ceph的各种操作能力与k8s存储系统的结合.调用第三方存储ceph的接口或命令,从而提供ceph数据卷的创建/删除.挂载/解除 ...
- 译<容器网络中OVS-DPDK的性能>
译<容器网络中OVS-DPDK的性能> 本文来自对Performance of OVS-DPDK in Container Networks的翻译. 概要--网络功能虚拟化(Network ...
- LGP3709题解
题目大意 简化后为区间众数出现次数,简化前为[数据删除] 吐槽 为什么题解只有一篇分块,剩下的全是莫队? 这题不是蒲公英?这和算导例题有何区别??? 为什么现在的人都喜欢去看题解而不注重思维??? 莫 ...
- Apache+PHP+Mysql安装手册(Windows)
一,准备安装包 下载地址: Apache:HTTPS://www.apachelounge.com/download/ PHP:http://php.net/downloads.php MySQL h ...
- CF1545X Codeforces Round #732
A. AquaMoon and Strange Sort 叉人题 如果数字各不相同,只需要统计每个数参与构成的逆序对总数,如果是奇数一定最终朝左,偶数朝右.无意义的数字交换对方向是没有影响的 继续考虑 ...