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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:54:33+00:00 2026-06-13T09:54:33+00:00

I need to check whether given binary file has write access or not. File

  • 0

I need to check whether given binary file has write access or not. File class API has a bug and its fixed in JDK7 but I can not just upgrade to it.

Here is the link to the bug: https://bugs.java.com/bugdatabase/view_bug?bug_id=6203387

When I open a FileOutputStream it corrupts the binary files and Explorer shows their size as zero and can not launch it. Here is the code snippet.

OS: Win7

Please help me to understand why just opening an output stream (not writing anything) corrupts a binary file. Is there any work around for this problem?

Here is the code snippet:

private boolean hasWriteAccess(File file) {
    FileOutputStream fos = null; 
    try {
        fos = new FileOutputStream(file);
    } catch (Exception e) {
        e.printStackTrace();
        if(fos != null) {
            try {
                fos.close();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        }
        return false;
    }
    return true;
}
  • 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-06-13T09:54:34+00:00Added an answer on June 13, 2026 at 9:54 am

    When I open a FileOutputStream it corrupts the binary files and Explorer shows their size as zero

    It doesn’t corrupt the file – it truncates it.

    If you want to open it in “append” mode, use the constructor overload which allows that:

    fos = new FileOutputStream(file, true);
    

    Looking at your code, that’s almost certainly what you want to do.

    As Andrew says, you should always close the stream too.

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

Sidebar

Related Questions

I'm very new to PHP. I need to check whether a given string has
I need to check whether a given date is in the preceding month for
What I need is to check whether a given string partially matches a given
I need to check whether a given host is replying to HTTP web requests.
I need check whether a given array will match another array. I can't figure
I need to check programmatically (in .NET) whether a given user (domain account) is
I need to check whether mysql is running or no on a given host.
I want check whether a logged in user has permissions like write or Read
I need to check whether a URL (represented by a NSURL) is available or
I need to check whether a string contains any swear words. Following some advice

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.