import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
public class Demo2 {
public static void main(String[] args) {
try {
writeDemo();
readDemo();
} catch (Exception e) {
e.printStackTrace();
}
}
private static void writeDemo() throws Exception{
DataOutputStream out=new DataOutputStream(new FileOutputStream("files/date.txt"));
for(int i=1;i<100;i++){
out.writeInt(i);
}
}
private static void readDemo() throws Exception{
File file=new File("files/date.txt");//files\\buf.txt
if(!file.exists()){
System.out.println("文件不存在。。。");
return ;
}
DataInputStream in=null;
in=new DataInputStream(new FileInputStream(file));
while (in.available()>0) {
int i = in.readInt();
if(i!=1&&i%50==1){
System.out.println();
}
System.out.print(i + " ");
}
}
}
java--包装类(DataInputStream,DataOutputStream )
最新推荐文章于 2022-09-15 14:36:51 发布