91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 359KB
    文件類型: .rar
    金幣: 2
    下載: 0 次
    發布日期: 2021-05-29
  • 語言: Java
  • 標簽: SMB??Java??遠程下載??

資源簡介

JAVA通過SMB的方式下載、上傳遠程Linux服務器的文件

資源截圖

代碼片段和文件信息

package?com.yzj.demo;
import?java.io.BufferedInputStream;??
import?java.io.BufferedOutputStream;??
import?java.io.File;??
import?java.io.FileInputStream;??
import?java.io.FileOutputStream;??
import?java.io.IOException;??
import?java.io.InputStream;??
import?java.io.OutputStream;??

import?org.apache.log4j.Logger;

import?com.yzj.log.LogFactory;
??
import?jcifs.smb.SmbFile;??
import?jcifs.smb.SmbFileInputStream;??
import?jcifs.smb.SmbFileOutputStream;??
??
public?class?RemoteAccessData?{??

private?static?Logger?logger?=?LogFactory.getInstance(RemoteAccessData.class);
??
????/**?
?????*?@param?args?
?????*?@throws?IOException??
?????*/??
????public?static?void?main(String[]?args)?throws?IOException?{??
????
???? smbGet(“smb://username:password@11.132.3.13/prlife_ls_yanshou1_image/001/2013/12/05/10/00000053085901001/1/00000053085901001001.tif“?“D:/download“);
????}??
????
????/**?
?????*?路徑格式:smb://192.168.75.204/test/新建?文本文檔.txt?
?????*??????????smb://username:password@192.168.0.77/test?
?????*?@param?remoteUrl?
?????*????????????遠程路徑?
?????*?@param?localDir?
?????*????????????要寫入的本地路徑?
?????*/??
????public?static?void?smbGet(String?remoteUrl?String?localDir)?{??
????
????????InputStream?in?=?null;??
????????OutputStream?out?=?null;??
????????
????????try?{??
????????
????????????SmbFile?remoteFile?=?new?SmbFile(remoteUrl);??
????????????
????????????if?(remoteFile?!=?null?&&?remoteFile.exists())?{??
????????????
???????????? String?fileName?=?remoteFile.getName();??
????????????????File?localFile?=?new?File(localDir?+?File.separator?+?fileName);??
????????????????in?=?new?BufferedInputStream(new?SmbFileInputStream(remoteFile));??
????????????????out?=?new?BufferedOutputStream(new?FileOutputStream(localFile));??
????????????????byte[]?buffer?=?new?byte[1024];??
????????????????while?(in.read(buffer)?!=?-1)?{??
????????????????????out.write(buffer);??
????????????????????buffer?=?new?byte[1024];??
????????????????}??
????????????}?else?{
????????????
???????????? //?文件不存在
???????????? logger.info(remoteUrl?+?“????文件不存在!“);
????????????}
????????????
????????}?catch?(Exception?e)?{??
????????????e.printStackTrace();??
????????}?finally?{??
????????
????????????try?{
out.close();
out?=?null;
}?catch?(IOException?e)?{
e.printStackTrace();
}?finally?{

try?{
in.close();
}?catch?(IOException?e)?{
e.printStackTrace();
}
}
????????}??
????}??
??
????/**
?????*?向共享目錄上傳文件??
?????*?@param?remoteUrl
?????*?@param?localFilePath
?????*/
????public?static?void?smbPut(String?remoteUrl?String?localFilePath)?{??
????
????????InputStream?in?=?null;??
????????OutputStream?out?=?null;?
????????
????????try?{??
????????
????????????File?localFile?=?new?File(localFilePath);??
????????????String?fileName?=?localFile.getName();??
????????????SmbFile?remoteFile?=?new?SmbFile(remoteUrl?+?“/“?+?fileName);??
??????????

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----

?????文件?????394990??2014-08-05?17:36??jcifs-1.3.14.jar

?????文件???????3795??2014-08-05?18:15??RemoteAccessData.java

-----------?---------??----------?-----??----

???????????????398785????????????????????2


評論

共有 條評論