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 6796477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:29:38+00:00 2026-05-26T18:29:38+00:00

I have an InputStream that is set up to handle local files, but want

  • 0

I have an InputStream that is set up to handle local files, but want to add the ability to read from a file over a network at a later time. I assume InputStream is geared for this already.

The problem I am having is, apparently InputStream is not guaranteed to have data available at any given time, and data may become available later. Not sure I’m understanding that correctly. There’s no method to determine an absolute size of available data (as number of bytes) or even if the InputStream is closed. It seems like if there’s a file there, it must have something available. A method that is handling the InputStream is probably going to read from it, and if no data is available, there isn’t any reason to keep it around. What’s worse is I can’t even tell if there is any data available.

So my question is, for a file being read over a network or locally, how can I determine if it is open/closed, and possibly determine the size of the file on the other end? Why is this class so bare?

  • 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-26T18:29:39+00:00Added an answer on May 26, 2026 at 6:29 pm

    The InputStream abstract class is for reading bytes from any source, not just a file. Its descendants provide methods for specific sources. For example, FileInputStream can be used to read bytes from a file, while SocketInputStream is used to read bytes from a socket.

    This is why InputStream doesn’t offer any methods for determining the file size, because it would make no sense for sources other than files.

    I’m not sure what exactly you mean by reading file over a network. If it means reading a file from a remote filesystem (e.g. over NFS), then you can use the length() method in the File class to get the size of the file:

    File file = new File("/path/to/file");
    System.out.println(file.length());
    

    You can determine whether the FileInputStream is open or not using the valid() method on the FileDescriptor instance obtained by calling the getFD() method on the ‘FileInputStream’ object:

    boolean isOpen(FileInputStream stream)
    {
        return stream.getFD().valid();
    }
    

    Of course, bear in mind that the Law of Leaky Abstractions applies.

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

Sidebar

Related Questions

I have a Service that downloads a file from the internet. What I want
I have a scanner set up that is working on an InputStream. I am
I have a method that reads a random joke from a file in raw,
In the emulator I'm trying to write to the file: /mnt/sdcard/Android/data/com.Me.MyApp/files/myFile.txt I have set
What InputStream type should be used to handle URLConnection streams that have HTTP Content-Encoding
I have this line in my program : InputStream Resource_InputStream=this.getClass().getClassLoader().getResourceAsStream(Resource_Name); But how can I
I have some code which I think should compile, but doesn't: import java.io.InputStream; import
I have a content provider that is custom to my set of Android applications,
I have some code that allows users to upload file attachments into a varbinary(max)
I have set up the code to call a remote server from Android app

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.