java copy file on network drive -


i'm trying copy files network drive folder, can access them online. file looks this, example

\\gvssqlvm\lieferscheine\20011023\volumed 5005.00000063.doc 

which can access in windows explorer, when type address in.

and destination copy file be

c:\program files\jbossas\server\default\deploy\root.war\tmp\volumed 5005.doc 

i run trouble copying file following code:

        string doc_dir = "\\\\gvssqlvm\\lieferscheine\\20011023\\";         string doc_file = doc_dir.concat(doc.getuniquefilename());         file source = new file(doc_file);          string home_url = system.getproperty("jboss.server.home.url");         string home_dir = home_url.substring(5); // cut out preceding file:/         string tmp_dir = home_dir.concat("deploy/root.war/tmp/");         string dest_file = tmp_dir.concat(title);         file dest = new file(dest_file);          try {                 input = new fileinputstream(source);                 output = new fileoutputstream(dest);                 byte[] buf = new byte[1024];                 int bytesread;                 while ((bytesread = input.read(buf)) > 0) {                     output.write(buf, 0, bytesread);                 }         } {             input.close();             output.close();         } 

input null. read space character troublesome, , followed advice put source fileinputstream in quotes, new file seems screw whole filename into

c:\program files\jbossas\bin\'\gvssqlvm\lieferscheine\20011023\volumed 5005.00000063.doc' 

where seems write current path first, add given 1 one backslash less; , still doesn't find file. file.extists() yields false.

thank help!

try following code using jcif.jar:

public static boolean createcopyonnetwork(string domain,string username,string password,string src, string dest) throws exception {     //fileinputstream in = null;     smbfileoutputstream out = null;      bufferedinputstream inbuf = null;     try{         //jcifs.config.setproperty("jcifs.smb.client.disableplaintextpasswords","true");         ntlmpasswordauthentication authentication = new ntlmpasswordauthentication(domain,username,password); // replace actual values           smbfile file = new smbfile(dest, authentication); // note different format         //in = new fileinputstream(src);           inbuf = new bufferedinputstream(new fileinputstream(src));         out = (smbfileoutputstream)file.getoutputstream();         byte[] buf = new byte[5242880];         int len;         while ((len = inbuf.read(buf)) > 0){             out.write(buf, 0, len);         }     }     catch(exception ex)     {         throw ex;     }     finally{         try{             if(inbuf!=null)                 inbuf.close();             if(out!=null)                 out.close();         }         catch(exception ex)         {}     }     system.out.print("\n file copied destination");         return true; } 

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -