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
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
241 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
  • 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
constuctor calling other constructor 2 78
rebasing and merging used in SCM 1 78
J2SE 5.0 metadata 1 61
mysql jsp example issue 32 48
This article describes my battle tested process for setting up delegation. I use this process anywhere that I need to setup delegation. In the article I will show how it applies to Active Directory
There's a lot of hype surrounding blockchain technology. Here's how it works and some of the novel ways it' s now being used - including for data protection.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

840 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