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

推荐订阅源

Project Zero
Project Zero
月光博客
月光博客
Y
Y Combinator Blog
T
The Blog of Author Tim Ferriss
O
OpenAI News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Know Your Adversary
Know Your Adversary
Last Week in AI
Last Week in AI
S
Securelist
Engineering at Meta
Engineering at Meta
博客园 - 司徒正美
P
Privacy & Cybersecurity Law Blog
T
Tailwind CSS Blog
F
Fortinet All Blogs
博客园 - 三生石上(FineUI控件)
Scott Helme
Scott Helme
MyScale Blog
MyScale Blog
P
Proofpoint News Feed
云风的 BLOG
云风的 BLOG
C
Cisco Blogs
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
小众软件
小众软件
U
Unit 42
Microsoft Azure Blog
Microsoft Azure Blog
Hacker News: Ask HN
Hacker News: Ask HN
Hugging Face - Blog
Hugging Face - Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
SecWiki News
SecWiki News
宝玉的分享
宝玉的分享
P
Proofpoint News Feed
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
H
Hackread – Cybersecurity News, Data Breaches, AI and More
L
Lohrmann on Cybersecurity
IT之家
IT之家
Security Archives - TechRepublic
Security Archives - TechRepublic
I
InfoQ
S
Security @ Cisco Blogs
Webroot Blog
Webroot Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
F
Full Disclosure
D
Darknet – Hacking Tools, Hacker News & Cyber Security
The GitHub Blog
The GitHub Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Jina AI
Jina AI
Cyberwarzone
Cyberwarzone
人人都是产品经理
人人都是产品经理
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
B
Blog RSS Feed
Apple Machine Learning Research
Apple Machine Learning Research

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