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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T13:52:16+00:00 2026-06-02T13:52:16+00:00

I use FileOutputStream fos to create/append and write to a debug file in a

  • 0

I use FileOutputStream fos to create/append and write to a debug file in a separate thread:

   fos = new FileOutputStream(outputFile, true);
    if (!outputFile.exists()) {
    outputFile.createNewFile();
    }
    fos.write(string.getBytes());

This code keeps beeing called in a loop while the user might clear=delete the file anytime from another thread to start logging the debug output anew.

Now I am really surprised that when the file is beeing deleted this code runs through without raising any exceptions BUT nothing happens. ie the file is not beeing recreated nor is anything written anmore. All the “writes” are just lost.

Do I really have to check manually all the time whether the file has been deleted in the meanwhile myself before calling fos.write each time?

If the exception would work like expected, ie when writing to a deleted file, it would be just easier and cleaner.

  • 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-02T13:52:18+00:00Added an answer on June 2, 2026 at 1:52 pm

    This is totally OS dependent. On Windows, you wouldn’t be able to delete the file; but on UNIX-like systems, this is just how it works, independent of programming language. Given that a file can have multiple links which can be deleted independently, you should understand why this behavior makes sense. And it fact, it leads to easier and cleaner behavior than exploding when a file is deleted would.

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

Sidebar

Related Questions

I used the following code to create a file: FileOutputStream fos = app.openFileOutput(fileName, Context.MODE_WORLD_WRITEABLE);
I use range hader, but not create correct file. if I send Range bytes=0-8999
I found out that you can use something like this to create a file:
use Tk; my $mw=new MainWindow; $mw->geometry(1024x768); $mw->Scrolled(Text, -scrollbars => s, -width => 30,-height=>10)->pack( );
I have a BitSet and want to write it to a file- I came
FileInputStream reads all bytes of a file and FileOutputStream writes allbytes to a file
[Assignment] Requirement Use specifically OutputStream subclasses to output data to a .txt file, that
I use the following code to save Chinese characters into a .txt file, but
I'm trying to use NIO to assemble a file out of several smaller files,
I'm trying to use cmd.exe to search for a file in a specific directory

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.