2015天籁k歌下载安装可以装车载WIFI吗

关于使用java通过 FTP 上传文件,总结 - 年华耗尽,繁星满地。 - ITeye技术网站
博客分类:
1、需要引入包
&& commons-net-ftp-2.0.jar
2、部分代码如下:
import mons.io.IOU
import mons.net.ftp.FTPC
import sun.net.ftp.FtpC
import sun.net.ftp.FtpLoginE
import java.io.F
import java.io.FileInputS
import java.io.IOE
import java.io.FileOutputS
import java.util.ResourceB
* @author 赵永恩
public class FtpFile {
public static String FtpIp = "192.168.1.100";
public static int port = 21;
public static String FtpUser = "admin";
public static String FtpPwd = "password";
public static String Ftppath = "/FTP_file/VID/";
* 测试方法
* 上边的信息,可以写在配置文件中,通过读取配置文件来获取
读取配置文件方法如下:
ResourceBundle bundle = ResourceBundle.getBundle("FilePathConfig");//FilePathConfig.properties配置文件的获取路径
* String FtpIp = bundle.getString("FtpIp");
String port = bundle.getString("port");
* @param args
public static void main(String[] args) {
String filename = "zykgl_yong.dmp";
String localpath = "D:\\zykgl.dmp";
testUpload(localpath,Ftppath,filename);
testDownload(localpath,Ftppath,filename);
fileNames();
* 连接判断的方法
* @param RWFileDir
* @param hostname
* @param port
* @param uid
* @param pwd
public static String connect(String RWFileDir,String hostname,int port,String uid,String pwd) {
String a="fail";
System.out.println("正在连接"+hostname+",请等待....");
aftp = new FtpClient(hostname,port);
aftp.login(uid,pwd);
aftp.binary();
a = "连接主机:"+hostname+"成功!";
a="connectSuccess";
} catch(FtpLoginException e){
a="登陆主机:"+hostname+"失败!请检查用户名或密码是否正确:"+e;
} catch (IOException e){
a="连接主机:"+hostname+"失败!请检查端口是否正确:"+e;
}catch(SecurityException e){
a="无权限与主机:"+hostname+"连接!请检查是否有访问权限:"+e;
* FTP上传单个文件测试
public static void testUpload(String localpath,String Ftppath,String filename) {
FTPClient ftpClient = new FTPClient();
FileInputStream fis =
ftpClient.connect(FtpIp,port);
ftpClient.login(FtpUser, FtpPwd);
File srcFile = new File(localpath);
fis = new FileInputStream(srcFile);
//设置上传目录
ftpClient.changeWorkingDirectory(Ftppath);
ftpClient.setBufferSize();
ftpClient.setControlEncoding("utf-8");
//设置文件类型(二进制)
ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
ftpClient.storeFile(filename, fis);
// 关闭输入流
fis.close();
// 退出ftp
ftpClient.logout();
System.out.println("====上传成功====");
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("FTP客户端出错!", e);
} finally {
IOUtils.closeQuietly(fis);
ftpClient.disconnect();
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("关闭FTP连接发生异常!", e);
* FTP下载单个文件测试
public static void testDownload(String localpath,String Ftppath,String filename) {
FTPClient ftpClient = new FTPClient();
FileOutputStream fos =
ftpClient.connect(FtpIp,port);
ftpClient.login(FtpUser, FtpPwd);
String remoteFileName = Ftppath+
fos = new FileOutputStream(localpath);
ftpClient.setBufferSize(1024);
//设置文件类型(二进制)
ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
ftpClient.retrieveFile(remoteFileName, fos);
fos.close();
ftpClient.logout();
System.out.println("====下载成功====");
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("FTP客户端出错!", e);
} finally {
IOUtils.closeQuietly(fos);
ftpClient.disconnect();
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("关闭FTP连接发生异常!", e);
* 读取目录下所有文件并下载
public static void fileNames(){
FTPClient ftpclient = new FTPClient();
ftpclient.connect(FtpIp);
ftpclient.login(FtpUser, FtpPwd);
String[] nameList = ftpclient.listNames();
for(int i = 0 ; i & nameList. i++){
String filename = new String(nameList[i].getBytes("iso-8859-1"));//文件名中文转换iso-8859-1,utf-8
System.out.println(filename+nameList[i]);
String localpath = "F:\\"+//下载后重建文件名
FileOutputStream fos =
String remoteFileName = "/"+nameList[i]; //服务器上文件名
if (1&0) {
fos = new FileOutputStream(localpath);
ftpclient.setBufferSize(204800);
//设置文件类型(二进制)
ftpclient.setFileType(FTPClient.BINARY_FILE_TYPE);
ftpclient.retrieveFile(remoteFileName, fos);
fos.close();
ftpclient.logout();
}catch(Exception e){
e.printStackTrace();
配置文件如下:
FtpIp=192.168.1.100
ftp_port=21
FtpUser=admin
FtpPwd=password
Ftppath=/FTP_file/VID/
下载次数: 48
浏览: 104710 次
来自: 成都
谢谢分享哦
转换为0字节
chensong215 写道转换时速度太慢了这个是有一点,使用java操作FTP服务器上的文件 - 书生 - ITeye技术网站
博客分类:
最近的工作中,需要定时操作FTP服务器上的文件,用到了FTPClient
记录并分享一下使用心得
首先当然是引包
commons-net-2.0.jar
这样你就可以使用FTPClient这个类创建用于连接FTP服务器的对象了
具体方法见代码:
FTPClient ftpClient = new FTPClient();
private String serverIP;
private Integer
以下是连接到FTP服务器的代码,返回true
就代表ftpClient已经成功连接到FTP服务器了,也就是可以操作FTP服务器上的文件了
public boolean getReady(){
boolean succeed =
int replyC
ftpClient.connect(this.serverIP, this.port);
replyCode = ftpClient.getReplyCode();
if(FTPReply.isPositiveCompletion(replyCode)) {
succeed = ftpClient.login(this.username, this.password);
if(!succeed){
log.error("ftp login error:"+ftpClient.getReplyString());
log.debug("FTP Server "+ this.serverIP +" is Connected......");
} catch (Exception exp) {
log.error("connect ftp server error:"+this.serverIP+" "+exp.getMessage());
if(ftpClient.isConnected()){
this.disConnect();
下面再来两个操作文件的方法做演示
获取文件列表(当然返回的是文件名集合)
public List&String& list(String filePath) {
List&String& result = new ArrayList&String&();
if (this.getReady()) {
files = ftpClient.listFiles(filePath);
for (FTPFile file : files) {
if (file.isFile()) {
result.add(file.getName());
} catch (IOException e) {
log.error("gen file list error:" + filePath + "\r\n"
+ e.getMessage());
删除FTP指定文件(小心操作哦)
* 删除指定文件
* @param pathname
* @throws IOException
public void deleteFile(String pathname) {
if(this.getReady()){
this.ftpClient.deleteFile(pathname);
("成功删除数据========"+pathname);
} catch (Exception e) {
log.error("非法参数路径[" + pathname + "]", e);
以上只做简单介绍,希望对初次使用的有引导作用
(192.4 KB)
下载次数: 3
下载次数: 0
流浪书生gzs
浏览: 2199 次
来自: 山东
我也写过一个ftp的操作的例子:http://asialee. ...温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!&&|&&
LOFTER精选
网易考拉推荐
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
&& /*** Description: 从FTP服务器下载文件* @param url FTP服务器hostname* @param port&& FTP服务器端口* @param username FTP登录账号* @param password&& FTP登录密码* @param remotePath&& FTP服务器上的相对路径* @param fileName 要下载的文件名* @param localPath 下载后保存到本地的路径* @return*/public boolean downFile(String url, int port, String username,&&& String password, String remotePath, String fileName,&&& String localPath) {&& // 初始表示下载失败&& boolean success =&& // 创建FTPClient对象&& FTPClient ftp = new FTPClient();&& try {&&&&&& // 连接FTP服务器&&& // 如果采用默认端口,可以使用ftp.connect(url)的方式直接连接FTP服务器&&& ftp.connect(url, port);&&& // 登录ftp&&& ftp.login(username, password);&&& reply = ftp.getReplyCode();&&& if (!FTPReply.isPositiveCompletion(reply)) {&&&& ftp.disconnect();&&&&&&& } &&& // 转到指定下载目录&&& ftp.changeWorkingDirectory(remotePath);&&& // 列出该目录下所有文件&&& FTPFile[] fs = ftp.listFiles();&&& // 遍历所有文件,找到指定的文件&&& for (FTPFile ff : fs) {&&&& if (ff.getName().equals(fileName)) {&&&&& // 根据绝对路径初始化文件&&&&& File localFile = new File(localPath + "/" + ff.getName());&&&&& // 输出流&&&&& OutputStream is = new FileOutputStream(localFile);&&&&& // 下载文件&&&&& ftp.retrieveFile(ff.getName(), is);&&&&& is.close();&&&& }&&& }&&& // 退出ftp&&& ftp.logout();&&& // 下载成功&&& success =&& } catch (IOException e) {&&& e.printStackTrace();&& } finally {&&& if (ftp.isConnected()) {&&&& try {&&&&& ftp.disconnect();&&&& } catch (IOException ioe) {&&&& }&&& }&& }&&}
阅读(4295)|
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
历史上的今天
loftPermalink:'',
id:'fks_095',
blogTitle:'java利用commons net jar包实现文件ftp上传和下载功能',
blogAbstract:'转载自:
{if x.moveFrom=='wap'}
{elseif x.moveFrom=='iphone'}
{elseif x.moveFrom=='android'}
{elseif x.moveFrom=='mobile'}
${a.selfIntro|escape}{if great260}${suplement}{/if}
{list a as x}
推荐过这篇日志的人:
{list a as x}
{if !!b&&b.length>0}
他们还推荐了:
{list b as y}
转载记录:
{list d as x}
{list a as x}
{list a as x}
{list a as x}
{list a as x}
{if x_index>4}{break}{/if}
${fn2(x.publishTime,'yyyy-MM-dd HH:mm:ss')}
{list a as x}
{if !!(blogDetail.preBlogPermalink)}
{if !!(blogDetail.nextBlogPermalink)}
{list a as x}
{if defined('newslist')&&newslist.length>0}
{list newslist as x}
{if x_index>7}{break}{/if}
{list a as x}
{var first_option =}
{list x.voteDetailList as voteToOption}
{if voteToOption==1}
{if first_option==false},{/if}&&“${b[voteToOption_index]}”&&
{if (x.role!="-1") },“我是${c[x.role]}”&&{/if}
&&&&&&&&${fn1(x.voteTime)}
{if x.userName==''}{/if}
网易公司版权所有&&
{list x.l as y}
{if defined('wl')}
{list wl as x}{/list}

我要回帖

更多关于 天籁车载电脑系统重装 的文章

 

随机推荐