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
请问问题是出在哪里呢?
展开