zoukankan      html  css  js  c++  java
  • 20180805-Java DataInputStream类

    DataInputStream dis = DataInputStream(InputStream in);

    下面的例子演示了DataInputStream和DataOutputStream的使用,该例从文本文件test.txt中读取5行,并转换成大写字母,最后保存在另一个文件test1.txt中。

    import java.io.*

    public class Test{
    public static void main(String[] args) throws IOException{
    DataInputStream d = new DataInputStream(new
    FileInputStream("test.txt"));
    DataOutputStream out = new DataOutputStream(new
    FileOutputStream("tst1.txt"));

    String count;
    while((count = d.readLine())!=null){
    String u = count.toUpperCase();
    System.out.println(u);
    out.writeByte(u+" ,");
    }
    d.close();
    out.close();
    }
    }



    Java DataInputStream类

    数据输入流允许应用程序以与机器无关方式从底层输入流中读取基本 Java 数据类型。
    下面的构造方法用来创建数据输入流对象。

    另一种创建方式是接收一个字节数组,和两个整形变量 off、len,off表示第一个读取的字节,len表示读取字节的长度。


    方法描述
    public final int read(byte[] r, int off, int len)throws IOException
    从所包含的输入流中将 len 个字节读入一个字节数组中。如果len为-1,则返回已读字节数。

    Public final int read(byte [] b)throws IOException
    从所包含的输入流中读取一定数量的字节,并将它们存储到缓冲区数组 b 中。

    public final Boolean readBooolean()throws IOException,
    public final byte readByte()throws IOException,
    public final short readShort()throws IOException
    public final Int readInt()throws IOException
    从输入流中读取字节,返回输入流中两个字节作为对应的基本数据类型返回值。

    public String readLine() throws IOException
    从输入流中读取下一文本行。

    备注:随笔中内容来源于网上资料整理,仅供参考。

  • 相关阅读:
    分布式基础学习(1)--分布式文件系统
    吞吐量(Throughput)、QPS、并发数、响应时间(RT)对系统性能的影响
    单点登录SSO的实现原理
    Java基础学习总结——Java对象的序列化和反序列化
    谈谈Memcached与Redis
    Java并发集合的实现原理
    Head First 设计模式 第4章工厂模式
    CentOS Linux 系统 英文 改中文
    Red Hat 9.0 Linux 分辨率修改
    Head First 设计模式 第5章 单例模式
  • 原文地址:https://www.cnblogs.com/Alanf/p/9425943.html
Copyright © 2011-2022 走看看