Getting directory path to .class file containing main

后端 未结 4 767
有刺的猬
有刺的猬 2020-12-01 16:55

Is it possible to get the path to my .class file containing my main function from within main?

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-01 17:28

    That looks more like an end-user issue to me. Also consider the possible need to run multiple instances of any given application, and preventing users from doing so is going to become a major annoyance.

    If the problem is with temporary file conflicts, then just make sure all your temporary files have unique names. This, as I understand it, is the most common reason people feel a need to prevent multiple instances of their applications from running.

    P.S.: The java.io.File.createTempFile() methods are ideally suited for preventing temporary file conflicts because they automatically generate unique filenames.

提交回复
热议问题