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

推荐订阅源

T
Tailwind CSS Blog
大猫的无限游戏
大猫的无限游戏
L
LINUX DO - 热门话题
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
雷峰网
雷峰网
aimingoo的专栏
aimingoo的专栏
博客园_首页
MongoDB | Blog
MongoDB | Blog
V
V2EX
GbyAI
GbyAI
量子位
Microsoft Azure Blog
Microsoft Azure Blog
有赞技术团队
有赞技术团队
G
Google Developers Blog
云风的 BLOG
云风的 BLOG
B
Blog
Microsoft Security Blog
Microsoft Security Blog
S
SegmentFault 最新的问题
O
OpenAI News
N
News and Events Feed by Topic
博客园 - Franky
爱范儿
爱范儿
Forbes - Security
Forbes - Security
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V2EX - 技术
V2EX - 技术
Application and Cybersecurity Blog
Application and Cybersecurity Blog
N
News and Events Feed by Topic
N
News | PayPal Newsroom
Schneier on Security
Schneier on Security
Cloudbric
Cloudbric
Security Archives - TechRepublic
Security Archives - TechRepublic
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Recent Commits to openclaw:main
Recent Commits to openclaw:main
人人都是产品经理
人人都是产品经理
P
Privacy International News Feed
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
B
Blog RSS Feed
阮一峰的网络日志
阮一峰的网络日志
D
DataBreaches.Net
Last Week in AI
Last Week in AI
罗磊的独立博客
Spread Privacy
Spread Privacy
Recent Announcements
Recent Announcements
The Cloudflare Blog
Google DeepMind News
Google DeepMind News
AWS News Blog
AWS News Blog
The Register - Security
The Register - Security
Y
Y Combinator Blog
J
Java Code Geeks
I
Intezer

博客园 - 碟子 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 }