2
안녕 모두들 자바 데이터 입력 출력 스트림으로 연습하고 있습니다. 하지만 난 내 파일에 데이터 입력 스트림을 쓸 수있는이 문제를 해결할 수 있지만 읽을 수없는 방법을 모르는 것이 여기자바 입출력 스트림을 읽을 수 없습니다
내 코드입니다 :
public static void readDataIOStream(){
DataInputStream dataIn = null;
int i = 10;
double d = 1023.56;
boolean b = true;
try {
dataIn = new DataInputStream(
new FileInputStream("test.txt"));
i = dataIn.readInt();
System.out.println("Reading " + i);
d = dataIn.readDouble();
System.out.println("Reading " + d);
b = dataIn.readBoolean();
System.out.println("Reading " + b);
d = dataIn.readDouble();
System.out.println("Reading " + d);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}try {
dataIn.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void writeDataIOStream(){
DataOutputStream dataOut = null;
int i = 10;
double d = 1023.56;
boolean b = true;
try {
dataOut = new DataOutputStream(new FileOutputStream("test.txt"));
System.out.println("Writing " + i);
dataOut.write(i);
System.out.println("Writing " + d);
dataOut.writeDouble(d);
System.out.println("Writing " + b);
dataOut.writeBoolean(b);
System.out.println("Writing " + 12.2 * 7.4);
dataOut.writeDouble(12.2 * 7.4);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
try {
dataOut.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
여기에 오류가 :
java.io.EOFException
at java.io.DataInputStream.readFully(Unknown Source)
at java.io.DataInputStream.readLong(Unknown Source)
at java.io.DataInputStream.readDouble(Unknown Source)
at bytestream.DataIOStream.readDataIOStream(DataIOStream.java:108)
at bytestream.DataIOStream.main(DataIOStream.java:16)
Writing 10
Writing 1023.56
Writing true
Writing 90.28
Reading 172003324
Reading 8.029891292620447E283
Reading true
내가 데이터 입력 스트림
감사합니다. 내게 understant – tienvv1234
대신'dataOut.write (i);'가 없습니다. – Rustam