0

i use commons-net ftp tool to download files. But my file is bigger, so I want to print a progress bar to tell the user the progress of the program.i use /r to print single line process bar.it freeze in IDEA console, when the program end,it will print all information. but it is fine in terminal.

private static CopyStreamListener createListener(FTPFile file, long startTime){
        return new CopyStreamListener(){
            long totalSize = file.getSize();
            @Override
            public void bytesTransferred(final CopyStreamEvent event) {
                bytesTransferred(event.getTotalBytesTransferred(), event.getBytesTransferred(), event.getStreamSize());
            }

            @Override
            public void bytesTransferred(final long totalBytesTransferred,
                                         final int bytesTransferred, final long streamSize) {
                long nowTime = System.currentTimeMillis();
                float percent = (float)totalBytesTransferred/totalSize;
                long speed = totalBytesTransferred/(nowTime-startTime);

                String message="speed:"+speed+"KB/s\t"+new DecimalFormat("#%").format(percent)+"\r";
                System.out.print(message);
//                printProgress(startTime,totalSize,totalBytesTransferred);
            }
        };
    }
tangyh
  • 1
  • 1

0 Answers0