/**
* 读取和写入不同基本类型数据 *
* @throws IOException
*/
public static void main(String[] args) throws IOException {
try{
FileOutputStream out1=new FileOutputStream("c:\\myDoc\\hello.txt");
BufferedOutputStream out2=new BufferedOutputStream(out1);
DataOutputStream out=new DataOutputStream(out2);
out.writeByte(1);
out.writeLong(2);
out.writeChar('c');
out.writeUTF("hello");
out.close();
}catch(IOException e){
System.out.println("出错:"+e);
}
System.out.println("文件写入完成。");
System.out.println("文件开始读取。。。");
try{
FileInputStream in1=new FileInputStream("c:\\myDoc\\hello.txt");
BufferedInputStream in2=new BufferedInputStream(in1);
DataInputStream in=new DataInputStream(in2);
System.out.println(in.readByte());
System.out.println(in.readLong());
System.out.println(in.readChar());
System.out.println(in.readUTF());

in.close();
}catch(IOException e){
System.out.println("出错:"+e);
}
System.out.println("文件读取完成。");

}

}

ReadAndWriteData的更多相关文章

  1. 推荐系统之矩阵分解及C++实现

    1.引言 矩阵分解(Matrix Factorization, MF)是传统推荐系统最为经典的算法,思想来源于数学中的奇异值分解(SVD), 但是与SVD 还是有些不同,形式就可以看出SVD将原始的评 ...

随机推荐

  1. mac上解决Resource temporarily unavailable

    Resource temporarily unavailable这种问题一般是因为当前的进程数或者文件数不够 fork: Resource temporarily unavailable 修改最大进程 ...

  2. 四、 添加模型Model(ASP.NET MVC5 系列)

    在这一章节中我们将添加一些classes类来管理数据库中的movies.这些classes类就是ASP.NET MVC应用程序中的"model". 我们将用.NET框架中的数据访问 ...

  3. python利用selenium和safari浏览器驱动实现新浪微博自动点赞 Demo

    import time from selenium import webdriver browser = webdriver.Safari() browser.get('http://weibo.co ...

  4. 【T-SQL】系列文章全文目录(2017-06-02更新)

    本系列[T-SQL]主要是针对T-SQL的总结. T-SQL基础 [T-SQL基础]01.单表查询-几道sql查询题 [T-SQL基础]02.联接查询 [T-SQL基础]03.子查询 [T-SQL基础 ...

  5. 翻译Algorithms Unlocked

    写在前面 本书是由<算法导论>(Introduction to Algorithms)的作者之一Thomas H. Cormen编写的适合对算法感兴趣但自身基础又不好的同学阅读.很多人评价 ...

  6. 拥抱Node.js 8.0,N-API入门极简例子

    本文摘录自<Nodejs学习笔记>,更多章节及更新,请访问 github主页地址.欢迎加群交流,群号 197339705. N-API简介 Node.js 8.0 在2017年6月份发布, ...

  7. characterEncodingFilter作用

    package com.demo.test; import java.io.IOException; import javax.servlet.Filter; import javax.servlet ...

  8. 【JAVAEE学习笔记】hibernate03:多表操作详解、级联、关系维护和练习:添加联系人

    一.一对多|多对一 1.关系表达 表中的表达 实体中的表达 orm元数据中表达 一对多 <!-- 集合,一对多关系,在配置文件中配置 --> <!-- name属性:集合属性名 co ...

  9. struts2 Unable to load configuration. - bean - jar:file:struts2-core-2.2.3.jar!/struts-default.xml:29:72

    今天启动tomcat的时候发现如下错误记录一下! 从stackoverflow上找到 原因是加入了多个struts2包 删除相同的包即可!!

  10. Linux安装JDK完整步骤

    1.检查一下系统中的jdk版本 [root@localhost software]# java -version 显示: openjdk version "1.8.0_102" O ...