中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

Java 使用JCIFS訪問(wèn)網(wǎng)絡(luò)文件共享的工具類

2018-07-20    來(lái)源:open-open

容器云強(qiáng)勢(shì)上線!快速搭建集群,上萬(wàn)Linux鏡像隨意使用
public class UploadDownloadUtil
{

	/**
	 * 從共享目錄拷貝文件到本地
	 * @param remoteUrl 共享目錄上的文件路徑
	 * @param localDir 本地目錄
	 */
	public void smbGet(String remoteUrl, String localDir)
	{
		InputStream in = null;
		OutputStream out = null;
		try
		{
			SmbFile remoteFile = new SmbFile(remoteUrl);
			//這一句很重要
			remoteFile.connect();
			if (remoteFile == null)
			{
				System.out.println("共享文件不存在");
				return;
			}
			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];
			}
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		finally
		{
			try
			{
				out.close();
				in.close();
			}
			catch (IOException e)
			{
				e.printStackTrace();
			}
		}
	}

	/**
	 * 從本地上傳文件到共享目錄
	 * @Version1.0 Sep 25, 2009 3:49:00 PM
	 * @param remoteUrl 共享文件目錄
	 * @param localFilePath 本地文件絕對(duì)路徑
	 */
	public 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);
			in = new BufferedInputStream(new FileInputStream(localFile));
			out = new BufferedOutputStream(new SmbFileOutputStream(remoteFile));
			byte[] buffer = new byte[1024];
			while (in.read(buffer) != -1)
			{
				out.write(buffer);
				buffer = new byte[1024];
			}
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		finally
		{
			try
			{
				out.close();
				in.close();
			}
			catch (IOException e)
			{
				e.printStackTrace();
			}
		}
	}

	public static void main(String[] args)
	{
		UploadDownloadUtil test = new UploadDownloadUtil();
		// smb:域名;用戶名:密碼@目的IP/文件夾/文件名.xxx
		// test.smbGet("smb://szpcg;jiang.t:xxx@192.168.193.13/Jake/test.txt",
		// "c://") ;
		
//		test.smbPut("smb://szpcg;jiang.t:xxx@192.168.193.13/Jake",
//				"c://test.txt");
		
		
		//用戶名密碼不能有強(qiáng)字符,也就是不能有特殊字符,否則會(huì)被作為分?jǐn)嗵幚?		test.smbGet("smb://CHINA;xieruilin:123456Xrl@10.70.36.121/project/report/網(wǎng)上問(wèn)題智能分析助手使用文檔.doc",
		"c://Temp/");

	}

}

標(biāo)簽: 域名

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請(qǐng)聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請(qǐng)與原作者聯(lián)系。

上一篇:用Alamofire進(jìn)行網(wǎng)絡(luò)請(qǐng)求

下一篇:類似log4cplus的一個(gè)C++日志類