Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5951763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:35:03+00:00 2026-05-22T17:35:03+00:00

I am trying to write values greater than 256 using DataOupPutStream.write() method. When i

  • 0

I am trying to write values greater than 256 using DataOupPutStream.write() method. When i try reading the same value using DataInputStream.read() it will return 0. So, i used DataOutputStream.writeInt() and DataInputStream.readInt() methods to write and retrieve values greater than 256 and it is working fine.

Refer the below code snippet i would like to know the behaviour of the compiler as what it does in the in.readInt() inside the while statement.

FileOutputStream fout = new FileOutputStream("T.txt");
BufferedOutputStream buffOut = new BufferedOutputStream(fout);
DataOutputStream out = new DataOutputStream(fout);

Integer output = 0;
out.writeInt(257);
out.writeInt(2);
out.writeInt(2123);
out.writeInt(223);
out.writeInt(2132);
out.close();

FileInputStream fin = new FileInputStream("T.txt");
DataInputStream in = new DataInputStream(fin);

while ((output = in.readInt()) > 0) {
    System.out.println(output);
}

The Output when i ran this snippet is :

Exception in thread "main" java.io.EOFException
    at java.io.DataInputStream.readInt(Unknown Source)
    at compress.DataIOStream.main(DataIOStream.java:34)
257
2
2123
223
2132

But when i ran in debug mode i get the following output :

2123
223
2132
Exception in thread "main" java.io.EOFException
    at java.io.DataInputStream.readInt(Unknown Source)
    at compress.DataIOStream.main(DataIOStream.java:34)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T17:35:03+00:00Added an answer on May 22, 2026 at 5:35 pm

    The readInt() method is a method like any other. You are getting an EOFException because that’s what the Javadoc for readInt() says will happen when you reach the end of the file.


    When I run

    DataOutputStream out = new DataOutputStream(new FileOutputStream("T.txt"));
    out.writeInt(257);
    out.writeInt(2);
    out.writeInt(2123);
    out.writeInt(223);
    out.writeInt(2132);
    out.close();
    
    DataInputStream in = new DataInputStream(new FileInputStream("T.txt"));
    try {
        while (true) 
            System.out.println(in.readInt());
    } catch (EOFException ignored) {
        System.out.println("[EOF]");
    }
    in.close();
    

    I get this in normal and debug mode.

    257
    2
    2123
    223
    2132
    [EOF]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to read and write values in registry. I get return something
I'm trying to write an extension method that I can use to copy values
I am trying to write a procedure in Inno setup code using default values
I am using netbeans 6.9.1, Glassfish 3.1. I am trying to write some values
I am trying to write a simple regex to match a percentage value range
I'm trying to write a function : Input: Source range, Source value, output range,
Im reading values from a file and storing these values in a hashmap, using
Trying to write a code that searches hash values for specific string's (input by
I'm trying to write a UDF in C that inserts values into a table
I'm trying to write a Java routine to evaluate math expressions from String values

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.