java ftp 下载文件错误_java ftp批量下载异常

FTPFile[]ft=ftp.listFiles();for(inti=0;i

FTPFile[] ft = ftp.listFiles();

for (int i = 0; i < local_need.size(); i++) {

file = local_need.get(i);

for (int j = 0; j < ft.length; j++) {

ftpfile = ft[j];

if (ftpfile.getName().equals(file)) {

long remotesize = ftpfile.getSize();

File localFile = new File(localPath + "/" + file);

if (localFile.exists()) {

if(localFile.canExecute()){

localFile.delete();

}

System.out.println("Delete success");

FileOutputStream is = new FileOutputStream(

localFile, true);

FileInputStream size = new FileInputStream(

localFile);

long loaclsize = size.available();

//ftp.setRestartOffset(loaclsize);

InputStream in = ftp

.retrieveFileStream(new String(ftpfile

.getName().getBytes("GBK"),

"ISO-8859-1"));

long process = loaclsize / remotesize;

byte[] bytes = new byte[1024];

int c;

while (( c=in.read(bytes,0,1024)) > -1) {

is.write(bytes, 0, c);

is.flush();

loaclsize += c;

long nowProcess = loaclsize / remotesize

* 100;

if (nowProcess > process) {

process = nowProcess;

if (process % 10 == 0) {

this.progressBar

.setValue((int) nowProcess);

}

}

c = in.read(bytes);

}

bytes=null;

is.close();

in.close();

size.close();

System.gc();

this.progressBar.setValue(0);

System.out.println((new Date()) + "-->" + file

+ "-->" + loaclsize + " bytes"

+ " Download Successfully");

Thread.sleep(2000);

}

批量从FTP服务器上下载符合条件的文件,第一个文件下载成功,但是到了第二个文件就在while (( c=in.read(bytes,0,1024)) > -1) 这句报错了:Exception in thread "Thread-3" java.lang.NullPointerException

请问问题是出在哪里呢?

展开

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值