
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、java 远程文件对接(处博)以下代码即贴即用,第一次发博客,不足之处请大家多多指教! 1、配置文件:copyremotefperties src/perties 这里保存的都是键值对信息 interface name(no packgage) = implementation class 注重: a:【路径符号】【必需】是【/】【如:d:/home/publish】 b:【键key=值value】对【后面】【绝不允许有空格】【如:remote_host_ip=7】 remote_host_ip 远程机器ip login_account 远程机器
2、登录名 login_password 远程机器登录密码 share_doc_name 远程机器分享文件夹名(设置分享后必需授予读写权限) sourcepath 本地路径 targetpath 目标路径(真切路径=分享文件夹路径+目标路径) remote_host_ip=7 login_account=77 login_password=77 share_doc_name=vfs_home sourcepath=d:/home/publish targetpath=publish 2、导入jar包:jcifs-1.3.16.jar 3、读取配置文件中key对应的value类:
3、remoteconfigutil.java package com.remote; import java.io.ioexception; import java.util.properties; * 读取配置文件中key对应的value * author junjieqin public class remoteconfigutil private sing remote_host_ip; private string login_account; private string login_password; private string share_doc_name; private st
4、ring sourcepath; private string targetpath; /无参构造办法 public remoteconfigutil() try / 读取配置文件 properties prop = new properties(); prop.load(this.getclass().getclassloader().getresourceasstream("copyremotefperties"); / 按照 key 猎取 value remote_host_ip = prop.getproperty("remote_host_
5、ip"); login_account = prop.getproperty("login_account"); login_password = prop.getproperty("login_password"); share_doc_name = prop.getproperty("share_doc_name"); sourcepath = prop.getproperty("sourcepath"); targetpath = prop.getproperty("targetpath&
6、quot;); ch (ioexception e) e.printstacktrace(); public string getlogin_account() return login_account; public vo login_account(string login_account) login_account = login_account; public string getlogin_password() return login_password; public void setlogin_password(string login_password) login_pass
7、word = login_password; public string getremote_host_ip() return remote_host_ip; public void setremote_host_ip(string remote_host_ip) remote_host_ip = remote_host_ip; public string getshare_doc_name() return share_doc_name; public void setshare_doc_name(string share_doc_name) share_doc_name = share_d
8、oc_name; public string getsourcepath() return sourcepath; public void setsourcepath(string sourcepath) this.sourcepath = sourcepath; public string gettargetpath() return targetpath; public void settargetpath(string targetpath) this.targetpath = targetpath; 4、操作远程分享文件夹类: remotefileutil.java 按照需求挑选相应的
9、 method package com.remote; import java.io.bufferoutputstream; import java.io.bufferedreader; import java.io.file; import java.io.fileinputstream; import java.io.filenotfoundexception; import java.io.ioexception; import java.io.inputstream; import java.io.inputstreamreader; import java.io.outputstre
10、am; import .malfoedurlexception; import .unknownhostexception; import java.util.arraylist; import java.util.list; import jcifs.smb.smbexception; import jcifs.smb.smbfile; import jcifs.smb.smbfileinputstream; import jcifs.smb.smbfileoutputstream; /* * file name: remotefileutil.java * created by: junj
11、ieqin * checked in by: * date: 2011-9-6 * revision: 1.7 * description:操作远程分享文件夹类 * amendment history * modified date:2011-9-16 * modified by:junjieqin * change description:from local copy s to remote directory */ public class remotefileutil private arraylist filelist = new arraylist(); remoteconfigu
12、til rc = new remoteconfigutil(); private string remotehostip; /远程主机ip private string account; /登陆账户 private string password; /登陆密码 private string sharedocname; /分享文件夹名称 /* * 默认构造函数 public remotefileutil() this.remotehostip = rc.getremote_host_ip(); this.account = rc.getlogin_account(); this.password
13、 = rc.getlogin_password(); this.sharedocname = rc.getshare_doc_name(); /* * 构造函数 * param remotehostip 远程主机ip * param account 登陆账户 * param password 登陆密码 * param sharepath 分享文件夹路径 public remotefileutil(string remotehostip, string account, string password,string sharedocname) this.remotehostip = remote
14、hostip; this.account = account; this.password = password; this.sharedocname = sharedocname; /* * 对远程分享文件举行读取全部行 * param remotefilename 文件名 解释:参数为分享名目下的相对路径 * 若远程文件的路径为:sharedoctest.txt,则参数为test.txt(其中sharedoc为分享名目名称); * 若远程文件的路径为:sharedooctt.txt,则参数为doctext.txt; * return 文件的全部行 public list string re
15、adfile(string remotefilename) smbfile smbfile = null; bufferedreader reader = null; list string reltlines = null; /构建衔接字符串,并取得文件衔接 string constr = null; constr = "smb:/"+account+":"+password+""+remotehostip+"/"+sharedocname+"/"+remotefilename; try sm
16、bfile = new smbfile(constr); catch (malformedurlexception e) e.printstacktrace(); /创建reader try reader = new bufferedreader(new inputstreamreader(new smbfileinputstream(smbfile); catch (smbexception e) e.printstacktrace(); catch (malformedurlexception e) e.printstacktrace(); catch (unknownhostexcept
17、ion e) e.printstacktrace(); /循环对文件举行读取 string line; try line = reader.readline(); if(line != null line.length() 0) resultlines = new arraylist string while (line != null) resultlines.a(line); line = reader.readline(); catch (ioexception e) e.printstacktrace(); /返回 return resultlines; /* * 对远程分享文件举行写
18、入 * param is 本地文件的输入流 * param remotefilename 远程文件名 解释:参数为分享名目下的相对路径 * 若远程文件的路径为:sharedoctest.txt,则参数为test.txt(其中sharedoc为分享名目名称); * 若远程文件的路径为:sharedocdoctext.txt,则参数为doctext.txt; * return public boolean file(inputstream is,string remotefilename) smbfile smbfile = null; outputstream os = null; byte buffer = new byte1024*8; /构建衔接字符串,并取得文件衔接 string constr = null; constr = "smb:/"+account+":"+password+""+remotehostip+"/"+sharedocname+"/"+remotefilename; try smbfile = new s
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 帮别人车辆过户委托书
- 文秘工作心得体会
- 2024年湘中幼儿师范高等专科学校辅导员考试真题
- 历史城市文化政策研究基础知识点归纳
- 2025年产品开发和设计阶段试题
- 智慧空间下高校学生未来学习需求分析
- 特种纸企业经营管理方案
- 2025至2030年中国电动遥控双开门控制器行业投资前景及策略咨询报告
- 2025至2030年中国珐琅门行业投资前景及策略咨询报告
- 小学六年级作文写事
- MOOC 数据挖掘与python实践-中央财经大学 中国大学慕课答案
- 2024年中考语文复习考点帮考点四 标点符号(解析版)
- 2023年老年病科半年工作总结报告
- 混合式学习中的大数据分析策略
- 2024年贵州西南能矿建设工程有限公司招聘笔试参考题库含答案解析
- 曲臂车安全专项施工方案
- 营销客户维护技巧与方法
- 23秋国家开放大学《金融模拟交易》实践报告书参考答案
- 偏差管理培训课件
- 《静脉输血规范》课件
- 康师傅财务分析报告
评论
0/150
提交评论