how to use a supplied username and password to read a file in Java -
I need to read a bunch of binary files from Java Script running Windows.
However, the folder in which files have limited permissions (ie my Windows username) is allowed to read them, but the user who runs Java (this is part of a web application) does not . If I pass my own username and Windows network password at runtime in Java, then what is the one way that I can read those files using my own permissions instead of a web user?
(Note that this web; This is a one time imported script that is running in the context of a web application.)
You can create a network share and then
import can connect via java.io.IOException; Import java.net.MalformedURLException; Import java.net.UnknownHostException; Import jcifs.smb.SmbException; Import jcifs.smb.SmbFileInputStream; Example of public squares {public static zero main (string [] args} {SmbFileInputStream fis = null; {Fis = new SmbFileInputStream ("smb: // DOMAIN; USERNAME: PASSWORD@SERVER/SHARE/filename.txt"); // handle as you would a normal input stream ... print the contents of this example file int length; Byte [] buffer = new byte [1024]; While ((length = fiss. Read (buffer)) = -1) {for (int x = 0; x; lt; length; x ++) {system.out.print ((four) buffer [x]) ; }}} Hold (malformedlexception e) {e.printStackTrace (); } Hold (unknownhostexception e) {e.printStackTrace (); } Grip (SMEE EXPLANATION) {e.printStackTrace (); } Hold (IOException e) {e.printStackTrace (); } Finally {if (fis! = Null} {try {fis.close (}}} hold (ignoring exception) {}}}}}
Comments
Post a Comment