Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jcifs.smb.SmbException: The system cannot find the file specified?

Tags:

java

smb

While running the below code i am getting the exception

jcifs.smb.SmbException: The system cannot find the file specified

Code:

public void m1(String b) throws IOException {
        // TODO Auto-generated method**strong text** stub

        BufferedReader br=null;
        String urlToBackUpFile = "smb://" +b +"/" + "c$/Program Files/Office/Config/OfficeSyncData.ini";
        String cp="smb://" +b +"/" + "c$/Program Files/Office/Config/OfficeSyncData.txt";
        System.out.println("smb folder of source file" + urlToBackUpFile);
        NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(null, "usrname", "passwd");


          SmbFile dir = new SmbFile(cp, auth);
          SmbFileInputStream in = new SmbFileInputStream( dir );
         // br = new BufferedReader(new InputStreamReader(in));


          System.out.println(dir.getDate());
          SmbFile dest = new SmbFile (urlToBackUpFile,auth);
          //count.copyTo(dest);
          dir.copyTo(dest);

    }

How do i resolve?.

like image 990
Kishore kumar Avatar asked Jul 10 '15 07:07

Kishore kumar


1 Answers

Without the entire stack trace I cannot be completely sure, but you may need to specify in the path the escape space character.

Try this:

String urlToBackUpFile = "smb://" +b +"/" + "c$/Program\\ Files/Office/Config/OfficeSyncData.ini";

And make sure that if "b" contains a space you do the same.

EDITED: also to try: can you point the path to a location that doesn't contain any spaces? that would prove if the space syntax is the source of your problems...

like image 198
gmcontessa Avatar answered Oct 03 '22 06:10

gmcontessa