Solved

How do I make it so after I create my file I can delete it without stopping tomcat?

Posted on 2003-11-16
4
243 Views
Last Modified: 2010-04-01
The code below creates a file called test.xml in C:\tmp. The problem im having is that I cant delete the file without stopping tomcat first. Gives me the windows error message "Cannot delete test:it is being used by another person or program".

How do I make it so after I create my file I can delete it without stopping tomcat?

Thanks in advance.

File dir = new File(File.separator + "tmp");
dir.mkdirs();
FileWriter filewriter1 = new FileWriter(File.separator + "tmp" + file.separator + "test.xml");

String szXMLString="this is a test";

filewriter1.write(szXMLString);
 filewriter1.close();
0
Comment
Question by:auduin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 2

Expert Comment

by:neele
ID: 9761780
Something like below did u try b4??

File dir2 = new File(File.separator + "tmp" + File.separator + "test.xml");
          
if(dir2.delete())
     System.out.println("deleted");
else
     System.out.println("NOT deleted");

It shd be deleted..
0
 
LVL 14

Accepted Solution

by:
kennethxu earned 100 total points
ID: 9764995
you write process looks good to me, I think the problem might be in your read process. I believe you must be reading it in somewhere of your java code otherwise there is no point to create it. so check out the reading code and make sure you close the inputsteam.
0
 

Author Comment

by:auduin
ID: 9767520
You are totally correct kenneth.

Forgot to do br.close() after my br.readline().

Thank your for your help
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 9768362
It's my pleasure to help and glad to know your problem is solved :-)
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Help with LDAp login using jsp 6 120
hashcode is calculated on the basis of value object 2 131
Books that can get me started on JAVA 2 133
null output 3 59
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
An introduction to the wonderful sport of Scam Baiting.  Learn how to help fight scammers by beating them at their own game. This great pass time helps the world, while providing an endless source of entertainment. Enjoy!
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Suggested Courses

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question