jcifs(一):把本地文件复制到目标机器上

import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import jcifs.Config;
import jcifs.smb.SmbFile;
import jcifs.smb.SmbFileOutputStream;

public class cifstest {
    public static void main(String args[]) throws IOException{
       
        //如果目标机器在域中,需要配置smb.client
        Config.setProperty("jcifs.smb.client.username", "jinliyong");
        Config.setProperty("jcifs.smb.client.password", "1234.abcd");
        Config.setProperty("jcifs.smb.client.domain", "mydomain.com.cn");

        //读取本地文件
        FileInputStream fi = new FileInputStream("/root/TOMORROW.mp3");

        //输出到目标机器共享目录
        SmbFile f2 = new SmbFile("smb://192.168.12.127/Music/text.txt");
        SmbFileOutputStream sis = new SmbFileOutputStream(f2);
        OutputStream fout = new BufferedOutputStream(sis);
        byte b[] = new byte[5 * 1024];
        int len;
        while ((len = fi.read(b)) != -1) {
            fout.write(b, 0, len);
        }
        fout.flush();
        fout.close();
      
    }
}

猜你喜欢

转载自blog.csdn.net/jinold/article/details/4355539
今日推荐