Link to home
Start Free TrialLog in
Avatar of auduin
auduin

asked on

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

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();
Avatar of neele
neele

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..
ASKER CERTIFIED SOLUTION
Avatar of kennethxu
kennethxu

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of auduin

ASKER

You are totally correct kenneth.

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

Thank your for your help
It's my pleasure to help and glad to know your problem is solved :-)