我正在使用Java 7 API提供的新“Files.copy [InputStream source,Path dest,REPLACE_EXISTING]”方法。
我正在将一个.dll从InputStream复制到C:\ Windows \ System32。显然,我需要管理员权限才能执行此操作。我正在使用管理员权限从命令提示符运行.jar文件,所以这应该不是问题。
当我尝试这样做时,我得到一个java.nio.file.AccessDeniedException。以下是整个堆栈跟踪的打印:
java.nio.file.AccessDeniedException: C:\Windows\System32\ICE_JNIRegistry.dll
at sun.nio.fs.WindowsException.translateToIOException(WindowsException.j
ava:83)
at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.jav
a:97)
at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.jav
a:102)
at sun.nio.fs.WindowsFileSystemProvider.newByteChannel(WindowsFileSystem
Provider.java:229)
at java.nio.file.spi.FileSystemProvider.newOutputStream(FileSystemProvid
er.java:430)
at java.nio.file.Files.newOutputStream(Files.java:170)
at java.nio.file.Files.copy(Files.java:2832)
at prerequirementform.PreRequirementForm.<init>(PreRequirementForm.java:
49)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstruct
orAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingC
onstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at com.izforge.izpack.installer.InstallerFrame.loadPanels(Unknown Source
)
at com.izforge.izpack.installer.InstallerFrame.<init>(Unknown Source)
at com.izforge.izpack.installer.GUIInstaller.loadGUI(Unknown Source)
at com.izforge.izpack.installer.GUIInstaller.access$100(Unknown Source)
at com.izforge.izpack.installer.GUIInstaller$2.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:727)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:688)
at java.awt.EventQueue$3.run(EventQueue.java:686)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDo
main.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:697)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThre
ad.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.
java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
非常感谢任何帮助。