package com.io.datestream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
/**
* DataInputStream,DataOutputStream
* 可以用于操作基本数据类型的数据的流对象
* @author zjw
*
*/
public class DataStream_class {
public static void main(String[] args) throws IOException {
// writeMethod();
// readMethod();
// writeUtf();
readUtf();
}
/*
* 读,设定编码格式utf-8修改版
*/
public static void readUtf() throws IOException{
DataInputStream dis=new DataInputStream(new FileInputStream("g:/java/utfup.txt"));
String str=dis.readUTF();
System.out.println(str);
dis.close();
}
/*
* 写,设定编码格式utf-8修改版
*/
public static void writeUtf() throws IOException{
DataOutputStream dis=new DataOutputStream(new FileOutputStream("g:/java/utfup.txt"));
dis.writeUTF("用这个写,就得用这个读");
dis.close();
}
/*
* 读取数据,
*/
public static void readMethod() throws IOException{
DataInputStream dis=new DataInputStream(new FileInputStream("g:/java/DataStream.txt"));
// String name=String.valueOf(dis.read());
int age=dis.readInt();
boolean boo=dis.readBoolean();
double dou=dis.readDouble();
// System.out.println("name:"+name);
System.out.println("age:"+age);
System.out.println("boo:"+boo);
System.out.println("dou:"+dou);
dis.close();
}
/*
* 写入数据,
*/
public static void writeMethod() throws IOException{
DataOutputStream dis=new DataOutputStream(new FileOutputStream("g:/java/DataStream.txt"));
// dis.write("王建伟".getBytes());
dis.writeInt(432);
dis.writeBoolean(true);
dis.writeDouble(455.776);
dis.close();
}
}
黑马程序员——用于操作基本数据类型的流对象
最新推荐文章于 2022-07-24 07:49:38 发布