java訪問共享文件夾


由於工作需要讀取局域網中一台機器的共享目錄中的文件,需要jcifs-1.1.11.jar的支持,使用SMB協議,以下是實現了遠程讀取文件的功能:

package junit;

import jcifs.smb.SmbFile;

/**   
 * java訪問共享目錄
 *
 * @author 林計欽
 * @version 1.0 2013-7-16 上午09:18:38   
 */
public class SmbTest {

    public static void main(String[] args) throws Exception {
        //smb://xxx:xxx@192.168.2.188/testIndex/  
        //xxx:xxx是共享機器的用戶名密碼
        String url="smb://192.168.2.188/testIndex/";
        SmbFile file = new SmbFile(url);
        if(file.exists()){
            SmbFile[] files = file.listFiles();
            for(SmbFile f : files){
                System.out.println(f.getName());
            }
        }
    }
}

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM