package i5ba.javase.io;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.ObjectInputStream;
import org.junit.jupiter.api.Test;
public class ObjectInputStreamTest {
@Test
public void test() {
FileInputStream fis = null;
BufferedInputStream bis = null;
ObjectInputStream ois = null;
try {
fis = new FileInputStream("fafa");
bis = new BufferedInputStream(fis);
ois = new ObjectInputStream(bis);
// ois.read
boolean temBoolean = ois.readBoolean();
System.out.println(temBoolean);
byte temByte = ois.readByte();
System.out.println(temByte);
char temChar = ois.readChar();
System.out.println(temChar);
double temDouble = ois.readDouble();
System.out.println(temDouble);
float temFloat = ois.readFloat();
System.out.println(temFloat);
long temLong = ois.readLong();
System.out.println(temLong);
int temInt1 = ois.readInt();
System.out.println(temInt1);
String temString = ois.readUTF();
System.out.println(temString);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
} finally {
if(ois != null) {
try {
ois.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e2) {
// TODO: handle exception
e2.printStackTrace();
}
}
}
}
}
java--ObjectInputStream--BufferedInputStream--FileInputStream代码简测
最新推荐文章于 2023-05-03 12:51:13 发布