EOFException - how to handle?

后端 未结 7 1150
迷失自我
迷失自我 2020-11-27 17:11

I\'m a beginner java programmer following the java tutorials.

I am using a simple Java Program from the Java tutorials\'s Data Streams Page, and at runtime, it keeps

7条回答
  •  情书的邮戳
    2020-11-27 17:34

    Alternatively, you could write out the number of elements first (as a header) using:

    out.writeInt(prices.length);
    

    When you read the file, you first read the header (element count):

    int elementCount = in.readInt();
    
    for (int i = 0; i < elementCount; i++) {
         // read elements
    }
    

提交回复
热议问题