java jcifs
来源:互联网 发布:淘宝厂家直销图标素材 编辑:程序博客网 时间:2024/06/11 20:06
Java 用JCIFS访问网络文件共享
JavaCC++C#
- 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 本地文件绝对路径
- */
- 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");
- //用户名密码不能有强字符,也就是不能有特殊字符,否则会被作为分断处理
- test.smbGet("smb://CHINA;xieruilin:123456Xrl@10.70.36.121/project/report/网上问题智能分析助手使用文档.doc",
- "c://Temp/");
- }
- }
0 0
- java jcifs
- jCIFS
- jCIFS
- JCIFS
- jCIFS
- jcifs
- JCIFS
- JCIFS
- Java操作远程共享资源(JCIFS)
- Java 用JCIFS访问网络文件共享
- java跨服务器保存文件:jcifs & FTP
- 通过jcifs实现java访问网络共享文件
- JCIFS--java通过域登录实现单点登录
- jcifs实现Java+AD的SSO解决方案,碰到的问题
- jcifs实现Java+AD的SSO解决方案,碰到的问题
- Java利用jcifs集成AD域用户认证
- Java通过jcifs集成AD域用户实现认证
- java远程发送文件到服务器(jcifs.smb实现方式)
- Git工具使用
- PHP学习第二天
- struts token
- 他们所未见过而又等待他们去发现的外界
- Vim学习笔记(2)vim 3.移动搜索 4.改动. 5.vim定制
- java jcifs
- mocall/free和new/delete的区别
- SQL 游标使用
- iOS程序警告:EXC_BAD_ACCESS(code=1
- Android之 ListActivity 的使用和在 ListView中添加图片文字
- Response.Cookies.Set() vs. Response.Cookies[] =
- 前端修炼手札:Chrome下CSS字体大小设置小于12px无效
- VMware Workstation[最强虚拟机] v9.0.2 完美中文汉化注册版 [五星]
- 在Java代码(非JSP及Action,Servlet,Controller)中获得WebRoot的物理路径