1

如何访问系统驱动器(我的意思是根)。 我需要这个,因为我必须复制我的程序运行所需的 exe 文件之一以复制到系统驱动器中。我通过将我的程序(jar)中的 exe 文件复制到系统驱动器来做到这一点,在我的情况下为(C:/file.exe)。 这是因为它完成了一些工作,例如操作注册表或使计算机进入睡眠状态。我还必须执行诸如关闭计算机之类的任务,但是我使用的是 shutdown.exe ,但是我找不到任何可以使计算机休眠或关闭显示器的方法每当我尝试这样做时,我得到的错误都是(拒绝访问) 或 (找不到文件)。我正在使用 netbeans... 在 jar 中创建它位于:jar name.jar\program name\file.exe 并在 java 文件中(即在 src 中):H:\src\program name\file 。可执行程序

我会对完成某些任务的替代方案感到满意。

4

1 回答 1

1

I would try to put the file in the jar as a resource, retrieve an inputstream to it with Class.getResourceAsStream() and write the stream to a File.

BTW, interesting idea to include .exe as resource in jar. But they only run on Windows, so how provide the same functions on other operating systems?

于 2013-09-06T15:09:51.253 回答