Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- try {
- FileOutputStream out1 = new FileOutputStream(new File(localFile));
- ftp.connect(host, port);
- ftp.login(username, password);
- FTPFile f = new FTPFile();
- //ftp.retrieveFile(file, out);
- InputStream in = ftp.retrieveFileStream(file);
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- byte[] buffer = new byte[1024];
- int bytesRead = 0;
- int current = 0;
- while ((bytesRead = in.read(buffer)) != -1) //keep filling the buffer until we get to the end of the file
- {
- out.write(buffer, current, bytesRead); //write the buffer to the file offset = current, length = bytesRead
- current += bytesRead; //we've progressed a little so update current
- setProgress((int)(current/size)*100); //tell progress how far we are
- }
- out.writeTo(out1);
- out.close();
- out1.close();
- in.close();
- } catch (Exception ex) {
- Logger.getLogger(DownloadThread.class.getName()).log(Level.SEVERE, null, ex);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement