2014-01-24 18 views
2

我正在試圖創建一個SmbFileInputStream,導致我的系統上存在一個目錄。我正在使用下面的代碼。每次我在第三次嘗試抓取時都會收到一個錯誤,它會向我顯示下面的堆棧跟蹤。我相信錯誤在於SMB網址的格式。如果有人能幫忙指出我的域名,服務器和用戶信息的配置錯誤,或者如何逃避下面的特殊字符,我將非常感激。SmbFileInputStream導致SmbException:SMB URL語法?

import java.io.FileInputStream; 
import java.io.FileNotFoundException; 
import java.io.FileOutputStream; 
import java.io.InputStream; 
import java.io.OutputStream; 
import jcifs.smb.*; 
import jcifs.*; 

public class jcifsX { 

    public static void main (String[] args){ 
     System.err.println("*********************************************************** loadWorkbookOrFail was ran"); 
     // create a new file input stream with the input file specified by fileName 

     jcifs.Config.registerSmbURLHandler(); 


     NtlmPasswordAuthentication npa = null; 
     try{ 
      npa = new NtlmPasswordAuthentication("myDomain","myUser","myPass"); 
      System.err.println("*********************************************************** NtlmPasswordAuthentication created successfully"); 
     } catch (Exception e) { 
      System.err.println("*********************************************************** Failed to create NtlmPasswordAuthentication. Stack trace to follow"); 
      e.printStackTrace(); 
     } 


     SmbFile smbf = null; 
     try{ 
      smbf = new SmbFile("smb:" + "//myDomain;myUser:[email protected]/myShare/" + args, npa); 
      System.err.println("*********************************************************** SmbFile successfully created"); 
      } 
     catch (Exception e) { 
      System.err.println("*********************************************************** Stack trace to follow"); 
      e.printStackTrace(); 
     } 


     SmbFileInputStream sfin = null; 
     try{ 
      sfin = new SmbFileInputStream(smbf); 
      System.err.println("*********************************************************** SmbFileInputStream successfully initiated"); 
      throw new IllegalArgumentException("If you're seeing this, it looks like it worked"); 
      } 
     catch (Exception e){ 
      System.err.println("*********************************************************** SmbFileInputStream failed: Stack trace to follow. args = " + args); 
      e.printStackTrace(); 
     } 
    } 
} 

我收到一旦運行這個堆棧跟蹤看起來像

jcifs.smb.SmbException: The system cannot find the file specified. 
    at jcifs.smb.SmbTransport.checkStatus(SmbTransport.java:563) 
    at jcifs.smb.SmbTransport.send(SmbTransport.java:663) 
    at jcifs.smb.SmbSession.send(SmbSession.java:238) 
    at jcifs.smb.SmbTree.send(SmbTree.java:119) 
    at jcifs.smb.SmbFile.send(SmbFile.java:775) 
    at jcifs.smb.SmbFile.open0(SmbFile.java:989) 
    at jcifs.smb.SmbFile.open(SmbFile.java:1006) 
    at jcifs.smb.SmbFileInputStream.<init>(SmbFileInputStream.java:73) 
    at jcifs.smb.SmbFileInputStream.<init>(SmbFileInputStream.java:65) 
    at jcifsX.main(jcifsX.java:61) 

預先感謝您向任何人願意花專門討論這一問題的任何時間。非常感謝。

回答

0

您使用過"smb:" + "//myDomain;myUser:[email protected]/myShare/" + args。這將產生像這樣的字符串smb://myDomain;myUser:[email protected]/myShare/[Ljava.lang.String;@470ae2bf

所以像這樣使用"smb:" + "//myDomain;myUser:[email protected]/myShare/" + args[0]。而不是0使用正確的索引。