How to choose the location of a log file for a Java application in a platform independent way?
问题 I'm writing a java application. Currently this produces a file called "trace.txt" in the same directory the .jar file lives. This can sometimes cause issue with file permissions, eg writing to C:\Program Files\Foo\trace.txt. After a bit of research on SO it seems the general opinion is to log to Application Data\Foo\ for the given user. This won't be the same location for other OS's. What's the best practice in this situation? I'm using java.util.logging. 回答1: You could always use the USER