打印流和数据流

package New_IO;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;

public class Test5 {
/**
* 数据流,专门用来做基本数据类型的读写的
* @param args
*/
public static void main(String[] args) {
try {
// Test5.testDataOutputStream(“F:\Java_project_new\src\New_IO\tt6.txt”);
Test5.testDataInputStream(“F:\Java_project_new\src\New_IO\tt6.txt”);
} catch (Exception e) {
e.printStackTrace();
}

}

/**
 * 数据输出流
 * 用数据输出流写到文件的中的基本数据类型的数据,是乱码的,不能直接辨认出来 需要数据输入流来读取
 */
public static void testDataOutputStream(String output) throws Exception{
    DataOutputStream out = new DataOutputStream(new FileOutputStream(output));

// out.writeBoolean(true);
out.writeDouble(1.44d);
out.flush();
out.close();
}

/**
 *数据输入流
 * 用数据输出流写到文件的中的基本数据类型的数据,是乱码的,不能直接辨认出来,需要数据输入流来读取
 * 用数据输入流读取数据输出流写到文件中的数据时,要保证使用和当时写的数据类型一致的类型来读取
 * 也就是说,如果写的时候是writeDouble,读的时候就得是readDouble
 *
 */
public static void testDataInputStream(String output)throws Exception{
    DataInputStream in = new DataInputStream(new FileInputStream(output));
    System.out.println(in.readDouble());
    in.close();
}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值