Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Self Deleting an application

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Plz. can anyone help me in deleting the application file after it has been closed.
I know I can use deleteOnExit() of java.io.File, but it doesn't seem to work in Windows.
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
why don't you delete the file in finalize() method of the Application class.
Regards,
Jelda
 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
heyas,
please note:
the finalize method is not necessarily going to be executed. it can/will be run by the JVM just before garbage collection, but unless you remove all ties to the object's reference, and manually call System.gc() then there is no garentee that this approach will work.
-twans
 
Ranch Hand
Posts: 585
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can't do that. Anything that is being run cannot be deleted as it is a process in use. What you could do (and this is dirty, bad architecture) is use Runtime.exec() to (on windows) use the "AT" command to schedule a delete command on your java code files. Again, this is not the best idea and it's platform dependant (so you'd have to have a way to do this on linux too - cron would do it).
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you launch the program from a bat or sh file?
 
francy thattil
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since I wanted an Application, I had created a .jar file with all .class files bundled in it. And i tried assigning a reference to this .jar file and use deleteOnExit() i.e.
import java.io.*;
public class DeleteMe {
public static void main(String[] args) throws Throwable {
File f = new File("DeleteMe.jar");
f.deleteOnExit();
}
}
But, still it does not budge(gets deleted) and remains still on the file system.
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Stan James:
Can you launch the program from a bat or sh file?


actually i it is del MyProgram.class & del this.bat ---> this may work(not too sure)
 
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ram Mohan:
<hr></blockquote>
actually i it is del MyProgram.class & del this.bat ---> this may work(not too sure)[/QB]


erase and del both will work.
 
I will suppress my every urge. But not this shameless plug:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic