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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:47:51+00:00 2026-05-13T09:47:51+00:00

I’m working in an application using Tomcat and servlets. There is a servlet (audioProcess)

  • 0

I’m working in an application using Tomcat and servlets.

There is a servlet (audioProcess) that receives the name of an mp3 file, that is played. This servlet also processes the mp3 file and stores the result in a txt file. The content of this txt will be replaced when the audioProcess servlet is invoked again (with a different mp3 file).

Everytime this servlet is invoked I delete the txt and I create a new one (containing information regarding the mp3 file). The name of the txt file is always the same.

My problem is that the txt file is never deleted. What I do to delete the file is:

File a = new File(path_clasificacion);

if(a.exists())
{
  boolean erased = a.delete();
  out.println("erased?" + erased);
}

The first time I invoke the servlet the txt file is erased. Only the first time. After deleting the txt file I try to write the new information in a txt file with the same name (stored in the same path). What happens is that the old file is not erased, the new information is added to the file.

Why can’t I delete the file?

Thanks

The txt file is generated using this code:

FileWriter f = null;
PrintWriter pw = null;

try
{
 f = new FileWriter(path,true);   
 pw = new PrintWriter(f);   
 pw.println(info);              
} catch (Exception e) {e.printStackTrace();

finally 
{
 f.close();
}
  • 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-13T09:47:52+00:00Added an answer on May 13, 2026 at 9:47 am

    You can’t erase the file so long as you have an open file handle to it.

    Look through your code and be sure to close() any streams or readers. This obviously includes making sure any references to it from MP3 digesting library code are also closed.

    “What about the first time?” you will ask. Answer: You got a positive status from the erase() call because the deletion request was successfully passed to the operating system. However, the OS is still twiddling its thumbs waiting for you to finally let go of the file. Thus, the file was not really (physically) deleted even the first time around.

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

Sidebar

Ask A Question

Stats

  • Questions 268k
  • Answers 268k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The original answer is no longer working as written: <%=Html.TextBox("test",… May 13, 2026 at 12:59 pm
  • Editorial Team
    Editorial Team added an answer You want to use .fetch(), not get(): entries = db.Query(Entry).order("-published").fetch()… May 13, 2026 at 12:59 pm
  • Editorial Team
    Editorial Team added an answer The strings and NSLog are working fine for me: NSLog(@"\\");… May 13, 2026 at 12:59 pm

Related Questions

I want use html5's new tag to play a wav file (currently only supported
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I've got a string that has curly quotes in it. I'd like to replace
In order to apply a triggered animation to all ToolTip s in my app,

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.