类型流DataInputstream 和DataOutputStream的用法

Posted windzly

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了类型流DataInputstream 和DataOutputStream的用法相关的知识,希望对你有一定的参考价值。

package test;
 
 
import java.io.*;
import java.sql.SQLClientInfoException;
import java.text.DateFormat;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.CountDownLatch;
import java.util.zip.InflaterInputStream;
 
import javax.annotation.processing.FilerException;
import javax.management.RuntimeErrorException;

import privateclass.Filterby_Name;
import privateclass.Filterby_hidden;
import privateclass.Filterby_java;
import privateclass.MyBufferedReader;
import privateclass.Person;
 
public class Main {
 
    private static final String space_operator = " ";
    private static final double pi = Math.PI;
    private static final String LINE_SEPARATOR = System.getProperty("line.separator");
	private static final int SIZE = 1024*1024;

	
    public static void main(String[] args) throws Exception {

    	doswrite();
    	disread();
    	
    	
    }


	public static void disread() throws FileNotFoundException, IOException {
		DataInputStream dis = new DataInputStream(new FileInputStream("data.txt"));
    	String string = dis.readUTF();
    	int a = dis.readInt();
    	System.out.println(string);
    	System.out.println(a);
	}


	public static void doswrite() throws FileNotFoundException, IOException {
		DataOutputStream dos = new DataOutputStream(new FileOutputStream("data.txt"));
    	//这个utf开头会带有标识所以只能用类型流读出
		dos.writeUTF("小朋友哥哥给你买糖吃");
    	dos.writeInt(99);
	}
}

  

以上是关于类型流DataInputstream 和DataOutputStream的用法的主要内容,如果未能解决你的问题,请参考以下文章

DataInputStream和DataOutputStream

Java中的DataInputStream和DataOutputStream的作用

JavaI/O:简单的使用DataOutputStream和DataInputStream操作文件流

Java 之 数据IO流-DataInputStream

JAVA DataOutputStream和DataInputStream

IO流之DataInputStream/DataOutputStream