【发布时间】:2015-09-24 01:00:31
【问题描述】:
我正在尝试在 appdata 目录中创建一个新文件,但我在类路径中使用的环境变量都不起作用。
我希望这个程序不仅仅可以在我的本地机器上运行,所以我不想硬编码那里的值,这就是我使用这些变量的原因。
如果我尝试命令
FileOutputStream outputStream = new FileOutputStream(new File("%HOMEDRIVE%//chromedriver.exe"));
或
FileOutputStream outputStream = new FileOutputStream(new File("%AppData%\\Local\\Temp"));
两个都报错
%HOMEDRIVE%\chromedriver.exe (The system cannot find the path specified)
有什么建议吗?
【问题讨论】:
-
您可以使用
System.getenv("APPDATA")动态检索appdata的路径
标签: java