【问题标题】:jcifs.smb.SmbException: The system cannot find the file specified?jcifs.smb.SmbException:系统找不到指定的文件?
【发布时间】:2015-09-28 20:24:33
【问题描述】:

运行以下代码时出现异常

jcifs.smb.SmbException: 系统找不到指定的文件

代码:

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);

    }

我该如何解决?

【问题讨论】:

  • 指定路径中是​​否有“b”?
  • b 的值是多少,异常指的是哪一行?

标签: java smb


【解决方案1】:

如果没有整个堆栈跟踪,我无法完全确定,但您可能需要在路径中指定转义空格字符。

试试这个:

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

并确保如果“b”包含一个空格,你也这样做。

已编辑:也可以尝试:您能否将路径指向不包含任何空格的位置?这将证明空格语法是否是您问题的根源...

【讨论】:

  • 如果你想以这种方式逃避它,你至少需要两个`\`,即program\\ files。并不是说它会有所帮助。
  • 抱歉,编辑了代码以包含双 '\' 。也许值得一试,因为 linux 终端的 shell 语言(即使在 windows 中模拟)需要空间转义
猜你喜欢
  • 2017-12-16
  • 1970-01-01
  • 2013-11-21
  • 2023-03-17
  • 2017-12-21
  • 2015-11-08
  • 2018-08-26
  • 2019-01-20
相关资源
最近更新 更多