Is it possible to access a开发者_如何学JAVA file (read/write/delete/move...) using different credentials then the one the logged in user?
Not directly from the JVM, no.
But under Windows, you could do exec()
with a RunAs
command, and under Unix/Linux/OS X you could do exec()
with sudo
. Though you may end up getting prompted for the password.
What's relevant is not the logged in user but the user under which the process is running - these are not necessarily the same.
However, running a process under a different user ID is very OS-specific, and there is no Java API for it. Besides, it would have to be done when the JVM starts up, as I do not think any OS allows a process to switch its user ID.
If it is available as a file share you can use jcifs
精彩评论