首页 > 编程知识 正文

java ioexception,FileOutputStream

时间:2023-05-05 04:52:59 阅读:165299 作者:132

Java DataInputStream readInt ()方法

Java.io.data inputstream.readint ) )用于读取输入字节并返回int值。

1语法

公共文件格式准备(

2参数

3返回值

此方法读取4个字节并返回int值。

4个样品

package com.yiidian;

//*

//*

import java.io.DataInputStream;

import java.io.DataOutputStream;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.qrdbq;

import java.io.InputStream;

公共类demo {

publicstaticvoidmain (stringyddargs ) throws qrdbq {

文件输出流fos=null;

inty dddi={ 128,250,430,520,820 };

try {

//create file output stream

fos=new file output stream (d : (test.txt ) );

//create数据输出流

dos=newdataoutputstream(fos );

//for each int in int buffer

for(intj:I ) {

//write int to data output stream

dos.writeint(j );

}

//forcedatatotheunderlyingfileoutputstream

dos.flush (;

//create file input stream

is=new file inputstream (d : (test.txt );

//create new data input stream

dis=newdataInputstream(is;

//可用流to be read

while(dis.available ) )0) {

//read four bytes from data input,return int

int k=dis.readInt (;

//打印int

system.out.print(k ' );

}

}catch(exceptione ) {

//if any error occurs

e .打印任务跟踪(;

} finally {

//releasesallsystemresourcesfromthestreams

if(is!=null )

is.close (;

if(dis!=null )

dis.close (;

if(fos!=null )

fos.close (;

if(dos!=null )

dos.close (;

}

}

}

128 250 430 520 820

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。