與windows explorer打開相同的文件相比,JCIFS默認狀況下要慢太多了。我找了大半天,總算找出瞭解決方法,增長以下配置,則讀取速度會有質的飛躍,我這邊從7s提高至0.2s: html
System.setProperty("jcifs.smb.client.dfs.disabled", "true");至於緣由嘛,我也不知道,我是今後網站撈到的一條配置:
http://samba.2283325.n4.nabble.com/Peformance-questions-td4644647.html java
執行程序代碼以下: windows
private static final int BUFFER_SIZE = 1024; public static void main(String[]args) throws Exception { //SmbFile file = new SmbFile("smb://finchina;daieel:123456@192.168.100.246/Soft/sc8 key.txt"); //SmbFile file = new SmbFile("smb://10.15.97.181/xx部資料庫/工做文檔/查詢邏輯.txt");d //http://samba.2283325.n4.nabble.com/Peformance-questions-td4644647.html System.setProperty("jcifs.smb.client.dfs.disabled", "true"); long startTime = System.currentTimeMillis(); UniAddress dc = UniAddress.getByName("192.168.100.5"); NtlmPasswordAuthentication authentication = new NtlmPasswordAuthentication("fgina", "xiajl", "orange"); SmbSession.logon(dc, authentication); SmbFile file = new SmbFile("smb://192.168.100.5/edse/users.txt", authentication); ByteArrayOutputStream out = new ByteArrayOutputStream(); BufferedInputStream in = new BufferedInputStream(new SmbFileInputStream(file)); //SmbFileInputStream in = new SmbFileInputStream(file) ; //創建smb文件輸入流 byte buffer[] = new byte[BUFFER_SIZE] ; int count = -1; while((count = in.read(buffer,0,BUFFER_SIZE)) != -1) { out.write(buffer, 0, count); } String content = new String(out.toByteArray(),"GBK"); in.close(); System.out.println(System.currentTimeMillis() - startTime); System.out.println(content); }