• DataInputStream和DataOutputStream


    操作基本数据类型的流

    DataInputStream

    DataOutputStream

    import java.io.DataInputStream;
    import java.io.DataOutputStream;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    
    public class IntegerDemo {
    	public static void main(String[] args) throws IOException {
    		myWrite();
    
    		myReader();
    	}
    
    	private static void myWrite() throws IOException {
    		// TODO Auto-generated method stub
    		// 创建数据输出流对象
    		FileOutputStream fos = new FileOutputStream("E:\zikao\file\cs.txt");
    		DataOutputStream dos = new DataOutputStream(fos);
    
    		// 写数据
    		dos.writeByte(10);
    		dos.writeShort(100);
    		dos.writeInt(1000);
    		dos.writeLong(10000);
    		dos.writeFloat(12.34F);
    		dos.writeDouble(12.56);
    		dos.writeChar('a');
    		dos.writeBoolean(true);
    
    		// 释放资源
    		dos.close();
    	}
    
    	private static void myReader() throws IOException {
    		// TODO Auto-generated method stub
    		// 创建数据输入流对象
    		FileInputStream fis = new FileInputStream("E:\zikao\file\cs.txt");
    		DataInputStream dis = new DataInputStream(fis);
    
    		// 读数据
    		byte b = dis.readByte();
    		short s = dis.readShort();
    		int i = dis.readInt();
    		long l = dis.readLong();
    		float f = dis.readFloat();
    		double d = dis.readDouble();
    		char c = dis.readChar();
    		boolean bl = dis.readBoolean();
    
    		// 释放资源
    		dis.close();
    
    		System.out.println(b);
    		System.out.println(s);
    		System.out.println(i);
    		System.out.println(l);
    		System.out.println(f);
    		System.out.println(d);
    		System.out.println(c);
    		System.out.println(bl);
    	}
    }
    
  • 相关阅读:
    flash盖住层的解决办法
    编译Chromium
    关于Ubuntu上的版本依赖问题
    GridBagLayout
    使用JList遇到的奇怪问题
    Swing常用整理
    Swing中改变Table的column大小
    SwingUtilities.invokeLater
    git常用命令
    小马过河(bupt 311)
  • 原文地址:https://www.cnblogs.com/denggelin/p/6341024.html
Copyright © 2020-2023  润新知