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
233 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
It's my pleasure to help and glad to know your problem is solved :-)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

HOW TO: Connect to the VMware vSphere Hypervisor 6.5 (ESXi 6.5) using the vSphere (HTML5 Web) Host Client 6.5, and perform a simple configuration task of adding a new VMFS 6 datastore.
In this article, I will show you HOW TO: Create your first Windows Virtual Machine on a VMware vSphere Hypervisor 6.5 (ESXi 6.5) Host Server, the Windows OS we will install is Windows Server 2016.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

728 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now