0

I want to make a button that closes and deletes the app file (.jar) when it is pressed. To do that I need to get the path of the file and then delete it but I dont know how to do it becouse I dont want to hardcode the path. Like, I can type the path in code and then delete the file but what if I change the location of the file? Then the path changes, thats why hardcoding the file path is useless in this case.

So here is the question: How do I get the path where the file is located in the moment the file is opened?

MarioML
  • 23
  • 7
  • You are referring to the jar file which contains the app which is doing the deleting? So you want to delete the implementation of the running app? Could you explain how this is not used to hide the running code? I ask because I have trouble imagining a use case which does NOT imply malicious code. – Yunnosch Jul 24 '19 at 23:41
  • 3
    This is almost certainly impossible in Windows, where the .jar file is likely to be locked. Why would you want to do this? Have you ever encountered an application that deletes itself before? – VGR Jul 24 '19 at 23:45
  • [You could try this.](https://stackoverflow.com/questions/320542/how-to-get-the-path-of-a-running-jar-file) It goes over how to find the path. – Aditya Agarwal Jul 24 '19 at 23:45
  • 1
    This is not possible in Windows as files that are in use (ie: a running application) are locked by the operating system from any changes, including deletion. If your JAR is running, it can't be deleted. Also, seconding what Yunnosch said, this gives me a very suspicious and creepy vibe ... – Zephyr Jul 24 '19 at 23:55
  • You could do this if your application starts an independent service or OS utility to handle such a thing. – DevilsHnd - 退職した Jul 25 '19 at 00:35
  • Why is this creepy, I just want to create a one time use application and I want it to delete itself. I think I have seen this before thats why I was asking how it can be done. – MarioML Jul 25 '19 at 00:39
  • I think it's creepy because I cannot think of a single legal reason for a one-time-use application. There may be one, I just can't think of one. – Zephyr Jul 25 '19 at 01:19

0 Answers0