文章会有【原创】或者【转载】标示,部分来自Google Baidu的学习结果 {Java/PHP/Python/Ruby/Go}

Java 在学习三十九【原创】  


输入:DataInputstream

输出:DataIOutputstream

package ioJava;


import java.io.DataInputStream;

import java.io.DataOutputStream;

import java.io.FileInputStream;

import java.io.FileOutputStream;


public class Test9 {


public static void main(String[] args) {

//write();

read();

}

public static void read() {

try {

DataInputStream d = new DataInputStream(

new FileInputStream("/Users/houhuiyang/Web/Java/data.log"));

System.out.println(d.readInt());

//System.out.println(d.readBoolean());

System.out.println(d.readUTF());

d.close();

} catch(Exception e) {

e.printStackTrace();

}

}

public static void write() {

try {

// .log文件作为字节输出流,并且可以写java类型

DataOutputStream din = new DataOutputStream(new FileOutputStream("/Users/houhuiyang/Web/Java/data.log"));

din.writeInt(1000);

din.writeBoolean(false);

din.writeUTF("中国北京");

din.close();

} catch (Exception e) {

e.printStackTrace();

}

}


}