在 Windows 上寻找存储临时 .class 文件的位置(Mac 上支持一些类似的应用程序)
可能的重复:
将文件存储在跨平台的用户目录中Java平台
我正在开发一个 java 项目,java 应用程序最终生成了一些 .class 文件。目前,这些文件存储在主应用程序目录内的项目目录中。在使用特定版本的 Novel 安全软件的网络上运行应用程序的某些人有时会在创建或修改这些 .class 文件时遇到问题。我想始终将这些文件存储在本地,但我不确定在 PC 版本上将它们存储在哪里。在 Mac 上,我想我会将它们存储在应用程序支持中,但我不知道 PC 上是否有类似的地方。另外,如果有一个适合 XP Vista 和 7 的位置是最好的,但如果我必须为每个操作系统提供特定的位置,那也足够了。
Possible Duplicate:
Storing a file in the user’s directory in cross-platform Java
I am working on a java project and the java application ends up making some .class files. Currently, these files are stored inside a projects directory inside the main application directory. Some people who run the application on a network with a certain version of Novel security software experience issues sometimes when these .class files are created or modified. I would like to instead always store these files locally but I am unsure of where to store them on the PC version. On the Mac I think I will store them in application support but I do not know of a similar place on the PC. Also, it would be best if there was a location that would be good for XP Vista and 7 but if I had to have specific locations for each OS that would be sufficient as well.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用%AppData%环境变量?我想你只需要把它添加到 CLASSPATH 中......
Use the %AppData% environment variable? I suppose you'd just need to add it to CLASSPATH...
如果应用程序在运行时生成这些文件,并且您不需要永久使用它们,您也可以将它们存储在临时目录中。您可以在 Java 中通过系统属性以独立于平台的方式访问临时目录:
System.getProperty("java.io.tmpdir")
。If the app is generating these at runtime, and you don't need them permanently you could also store them in the temp directory. You can access the temp directory in a platform independent way in Java via the system property:
System.getProperty("java.io.tmpdir")
.您可以查找“用户”目录。在该目录中,有一个“appData”目录。
在 Vista 上,它是“C:\Users\Username\AppData”。
在XP上,我不太记得这个名字了。但这些是 Windows 的特殊文件夹,因此我确信您可以指定一个名称并直接转到它。
You could look for the "user" directory. In that directory, there's an "appData" directory.
On Vista, it's "C:\Users\Username\AppData".
On XP, i don't quite remember the name. But These are special folders for Windows so I'm sure you can specify one name and go to it directly.