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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:24:36+00:00 2026-05-26T02:24:36+00:00

Here is a code snippet where I am opening a file for writing with

  • 0

Here is a code snippet where I am opening a file for writing with two FileOutputStreams at the same time.

FileOutputStream fis = null;
File openFile = new File("myfile");
try {
    fis = new FileOutputStream(openFile);
    Toast toast = Toast.makeText(getApplicationContext(), "Opened", Toast.LENGTH_SHORT);
    toast.show();
}
catch (FileNotFoundException e1) {
    Toast toast = Toast.makeText(getApplicationContext(), "FileNotFound", Toast.LENGTH_SHORT);
    toast.show();
}

// now try to open it again
FileOutputStream fis2 = null;
try {
    fis2 = new FileOutputStream(openFile);
    Toast toast = Toast.makeText(getApplicationContext(), "Opened2", Toast.LENGTH_SHORT);
    toast.show();
}
catch (Exception e1) {
    Toast toast = Toast.makeText(getApplicationContext(), "Exception: " + e1.getMessage(), Toast.LENGTH_SHORT);
    toast.show();
}

I end up getting two Toast messages, “Opened” and “Opened2”.

I need to make sure I don’t open a file for reading/writing/deleting that is currently open for writing by another instance. How to I ensure I do not modify a file that is currently open for writing?

  • 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-26T02:24:36+00:00Added an answer on May 26, 2026 at 2:24 am

    I need to make sure I don’t open a file for reading/writing/deleting
    that is currently open for writing by another instance.

    What do you mean by another instance?

    • If this is another thread in your application use the synchronization for read/write methods.
    • If this is another process created by yourself (application, service etc.) use exclusive FileLock to coordinate file read/write operations between processes.
    • If this is another process you don’t control (i.e. created by someone else) you can check whether file is currently opened by inspecting /proc/…/fd/ tree, as lsof utility does. However this usually requires you to have root privileges.

    Hope that give you a clue. Let me know if you need further assistance.

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

Sidebar

Related Questions

In the program I am writing, I have something similar to the code here:
i am opening a pop up from code behind(which i am using as waiting
EDIT: SOLVED--SOURCE CODE HERE: http://matthewdowney20.blogspot.com/2011/09/source-code-for-roku-remote-hack.html thanks in advance for reading and possibly answering this.
I read a few lines of code here where it looks to me like
I need to tell you that i'm very new to jquery and still learning,
I'm trying to experiment with using splice ( man 2 splice ) to copy
I have a view that I pass a viewmodel object to that contains an
I've a question with regard to android adapters. I have a class, extending BaseAdapter.
I recently realized that my modification to my website has caused sessions to stop
I allocated a number of labels and now I am trying to update 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.