惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

F
Fortinet All Blogs
Microsoft Security Blog
Microsoft Security Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Vercel News
Vercel News
Application and Cybersecurity Blog
Application and Cybersecurity Blog
C
Check Point Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
W
WeLiveSecurity
The Hacker News
The Hacker News
L
LINUX DO - 热门话题
T
Tenable Blog
Hugging Face - Blog
Hugging Face - Blog
Google Online Security Blog
Google Online Security Blog
博客园 - Franky
P
Proofpoint News Feed
H
Hacker News: Front Page
P
Privacy & Cybersecurity Law Blog
月光博客
月光博客
P
Proofpoint News Feed
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
The GitHub Blog
The GitHub Blog
云风的 BLOG
云风的 BLOG
博客园_首页
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
CERT Recently Published Vulnerability Notes
Forbes - Security
Forbes - Security
I
InfoQ
Stack Overflow Blog
Stack Overflow Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Attack and Defense Labs
Attack and Defense Labs
N
News and Events Feed by Topic
博客园 - 叶小钗
T
Threat Research - Cisco Blogs
aimingoo的专栏
aimingoo的专栏
D
Darknet – Hacking Tools, Hacker News & Cyber Security
小众软件
小众软件
大猫的无限游戏
大猫的无限游戏
MongoDB | Blog
MongoDB | Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Hacker News - Newest:
Hacker News - Newest: "LLM"
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 司徒正美
O
OpenAI News
G
Google Developers Blog
Martin Fowler
Martin Fowler
罗磊的独立博客
S
SegmentFault 最新的问题
T
Tor Project blog
量子位

博客园 - 碟子 QQ:9997452

SQL用例集锦 关于“点击这里继续访问您选择的百度XXX” 对【SQL SERVER 分布式事务解决方案】的心得补充 解决chrome浏览器安装扩展、应用程序一直处在“检查中”的问题 【转帖】科学对待 健康养猫 打造快乐孕妇 VBA一例:如何保持文本框焦点 FlashPaper 2 API 中文版 【转载】Windows 7 mklink命令详解 后网盘时代:网盘+同步=云存储 [2012年7月31日更新] 安装veket到移动硬盘NTFS分区 启用网络 DTC 访问 【腾讯通服务器的消息集成解决方案】之与勤哲Excel服务器的集成 CureIt! 简单Repack(去广告窗口) 解决Windows域管理的几个经典问题 【飘雪驱动器管理大师(USB禁用、USB加锁)】原理分析 关于ASP.NET中用Response.Write()方法响应导致页面字体变大的问题 用于HTTP加密浏览的TW2.0插件 Microsoft Windows Workflow Foundation 入门 Atlas 和 ASP.Net AJAX
【转载】通过java的jcifs类库访问网上邻居共享文件[代码]
碟子 QQ:9997452 · 2011-11-23 · via 博客园 - 碟子 QQ:9997452

转载自笨笨熊的BLOG:http://www.mkv8.com/?p=42

以下是通过java的jcifs类库,访问网上邻居上的共享文件代码。
相关类库下载地址:http://www.mkv8.com/?p=48


  1 public class UploadDownloadUtil
  2 {
  3 
  4  /**
  5   * 从共享目录拷贝文件到本地
  6   * @param remoteUrl 共享目录上的文件路径
  7   * @param localDir 本地目录
  8   */
  9  public void smbGet(String remoteUrl, String localDir)
 10  {
 11   InputStream in = null;
 12   OutputStream out = null;
 13   try
 14   {
 15    SmbFile remoteFile = new SmbFile(remoteUrl);
 16    //这一句很重要
 17    remoteFile.connect();
 18    if (remoteFile == null)
 19    {
 20     System.out.println("共享文件不存在");
 21     return;
 22    }
 23    String fileName = remoteFile.getName();
 24    File localFile = new File(localDir + File.separator + fileName);
 25    in = new BufferedInputStream(new SmbFileInputStream(remoteFile));
 26    out = new BufferedOutputStream(new FileOutputStream(localFile));
 27    byte[] buffer = new byte[1024];
 28    while (in.read(buffer) != -1)
 29    {
 30     out.write(buffer);
 31     buffer = new byte[1024];
 32    }
 33   }
 34   catch (Exception e)
 35   {
 36    e.printStackTrace();
 37   }
 38   finally
 39   {
 40    try
 41    {
 42     out.close();
 43     in.close();
 44    }
 45    catch (IOException e)
 46    {
 47     e.printStackTrace();
 48    }
 49   }
 50  }
 51 
 52  /**
 53   * 从本地上传文件到共享目录
 54   * @Version1.0 Sep 25, 2009 3:49:00 PM
 55   * @param remoteUrl 共享文件目录
 56   * @param localFilePath 本地文件绝对路径
 57   */
 58  public void smbPut(String remoteUrl, String localFilePath)
 59  {
 60   InputStream in = null;
 61   OutputStream out = null;
 62   try
 63   {
 64    File localFile = new File(localFilePath);
 65 
 66    String fileName = localFile.getName();
 67    SmbFile remoteFile = new SmbFile(remoteUrl + "/" + fileName);
 68    in = new BufferedInputStream(new FileInputStream(localFile));
 69    out = new BufferedOutputStream(new SmbFileOutputStream(remoteFile));
 70    byte[] buffer = new byte[1024];
 71    while (in.read(buffer) != -1)
 72    {
 73     out.write(buffer);
 74     buffer = new byte[1024];
 75    }
 76   }
 77   catch (Exception e)
 78   {
 79    e.printStackTrace();
 80   }
 81   finally
 82   {
 83    try
 84    {
 85     out.close();
 86     in.close();
 87    }
 88    catch (IOException e)
 89    {
 90     e.printStackTrace();
 91    }
 92   }
 93  }
 94 
 95  public static void main(String[] args)
 96  {
 97   UploadDownloadUtil test = new UploadDownloadUtil();
 98   // smb:域名;用户名:密码@目的IP/文件夹/文件名.xxx
 99   // test.smbGet("smb://szpcg;jiang.t:xxx@192.168.193.13/Jake/test.txt",
100   // "c://") ;
101   
102 //  test.smbPut("smb://szpcg;jiang.t:xxx@192.168.193.13/Jake",
103 //    "c://test.txt");
104   
105   
106   //用户名密码不能有强字符,也就是不能有特殊字符,否则会被作为分断处理
107   test.smbGet("smb://CHINA;xieruilin:123456Xrl@10.70.36.121/project/report/网上问题智能分析助手使用文档.doc",
108   "c://Temp/");
109 
110  }
111 
112 }