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

  • SEARCH
  • Home
  • 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 7416901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:35:33+00:00 2026-05-29T07:35:33+00:00

I am learning java from Java : Complete Reference. I am currently working on

  • 0

I am learning java from Java : Complete Reference.
I am currently working on the examples in the chapter : Input/Output : Exploring java.io
I dint understand few lines of code from the example below.
Can anyone help me with this example.

import java.io.*;

class FileInputStreamDemo
{
public static void main(String args[]) throws IOException
{
InputStream f = new FileInputStream("E://SomeRandomTextFile.txt");
System.out.println("Total available bytes : " + size = f.available());

int n = size/40;
System.out.println("First" + n + " bytes of file one read() at a time");

for(int i=0; i<n; i++)
{
System.out.println((char) f.read());
}

System.out.println("\n Still available: "+ f.available());
System.out.println("Reading the text " + n + " with one read(b[])");
byte b[] = new byte[n];

if(f.read(b) != n)
{
System.err.println("coudn't read" + n + "bytes.");
}
System.out.println(new String(b,0,n));
}

In the above code, I dint understand the last five lines of code.

What is the outcome of

f.read(b) 

What is

System.err

and

What is the outcome of

new String(b,0,n);
  • 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-29T07:35:35+00:00Added an answer on May 29, 2026 at 7:35 am

    Should be:

    if(f.read(b) != n)
    

    It’s a method call to read bytes from the file into the buffer. From javadoc:

    Reads some number of bytes from the input stream and stores them into
    the buffer array b.

    This line:

    new String(b,0,n);
    

    creates a new String from the bytes inside the buffer b, starting from index 0 and taking the next n bytes. From javadoc:

    Constructs a new String by decoding the specified subarray of bytes
    using the platform’s default charset.

    And finally this:

    System.err
    

    returns a reference to the program standard error stream.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am learning Java using the book Java: The Complete Reference. Currently I am
I'm learning Java EE currently (moving from SE) and I am confused about asynchronous
When I was learning Java coming from a background of some 20 years of
I just started learning C++ (coming from Java ) and am having some serious
Coming from PHP with some Java Struts 2.0 experience any tips/tricks on learning GWT?
I am learning Java, theres one thing I do not understand.. in the main
I'm learning java and I have made simple program that simply reads value from
I am learning Java (slowly) from the ground up, but every now and again
Learning java server technologies, trying to clarify some things. There are few technologies that
I am learning Java from scratch. I installed the JDK, and I got the

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.