摘要:数据流创建一个输入或者输出流只想底层的输入输出流 File file1=new File("test1.txt");
&n
数据流
创建一个输入或者输出流只想底层的输入输出流File file1=new File("test1.txt");
FileOutputStream out1=new FileOutputStream(file1);
DataOutputStream out11=new DataOutputStream(out1);
out11.writeInt(100);
out11.writeLong(100);
out11.writeFloat(3.14f);
out11.writeDouble(3.14);
out11.writeBoolean(true);
out11.writeChars("hello world ");
FileInputStream in1=new FileInputStream(file1);
DataInputStream in11=new DataInputStream(in1);
System.out.println(in11.readInt());
System.out.println(in11.readLong());
System.out.println(in11.readFloat());
System.out.println(in11.readDouble());
System.out.println(in11.readBoolean());
char c;
for(;(c=in11.readChar())!='\0';){
System.out.print(c);
}
对象流(克隆不改变原来引用)
try{
File file1=new File("test1.txt");
FileOutputStream out1=new FileOutputStream(file1);
ObjectOutputStream out2=new ObjectOutputStream(out1);
TV tv1=new TV();
out2.writeObject(tv1);
FileInputStream in1=new FileInputStream(file1);
ObjectInputStream in2=new ObjectInputStream(in1);
TV tv2=(TV)in2.readObject();
tv2.show();
} catch(IOException e){
System.out.println(e.toString());
} catch(ClassNotFoundException e2){//一定要写
System.out.println(e2.toString());
}