Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7746755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:21:35+00:00 2026-06-01T10:21:35+00:00

Can anybody see what is wrong with this code. it does not show up

  • 0

Can anybody see what is wrong with this code. it does not show up progress-bar but uploades all the files.
I did checkout sun tutorial and swingworkers also but i couldn’t fix it yet.

private static boolean putFile(String m_sLocalFile, FtpClient m_client) {
    boolean success = false;
    int BUFFER_SIZE = 10240;
    if (m_sLocalFile.length() == 0) {
        System.out.println("Please enter file name");
    }
    byte[] buffer = new byte[BUFFER_SIZE];
    try {
        File f = new File(m_sLocalFile);
        int size = (int) f.length();
        System.out.println("File " + m_sLocalFile + ": " + size + " bytes");
        System.out.println(size);
        FileInputStream in = new FileInputStream(m_sLocalFile);
        //test
        InputStream inputStream = new BufferedInputStream(
                      new ProgressMonitorInputStream(null,"Uploading " + f.getName(),in));

        //test
        OutputStream out = m_client.put(f.getName());

        int counter = 0;
        while (true) {
            int bytes = inputStream.read(buffer);  //in
            if (bytes < 0)
                break;
            out.write(buffer, 0, bytes);
            counter += bytes;
            System.out.println(counter);
        }

        out.close();
        in.close();
        inputStream.close();
        success =true;
    } catch (Exception ex) {
        System.out.println("Error: " + ex.toString());
    }
    return true;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T10:21:36+00:00Added an answer on June 1, 2026 at 10:21 am

    I think your code is fine.
    Maybe the task isn’t taking long enough for the progress bar to be needed?

    Here’s a modified version of your code which reads from a local file and writes to another local file.
    I have also added a delay to the write so that it gives the progress bar time to kick in.
    This works fine on my system with a sample 12MB PDF file, and shows the progress bar.
    If you have a smaller file then just increase the sleep from 5 milliseconds to 100 or something – you would need to experiment.

    And I didn’t even know that the ProgressMonitorInputStream class existed, so I’ve learnt something myself ;].

    /**
     * main
     */
    public static void main(String[] args) {
        try {
            System.out.println("start");
    
            final String inf = "d:/testfile.pdf";
            final String outf = "d:/testfile.tmp.pdf";
            final FileOutputStream out = new FileOutputStream(outf) {
                @Override
                public void write(byte[] b, int off, int len) throws IOException {
                    super.write(b, off, len);
                    try {
                        // We delay the write by a few millis to give the progress bar time to kick in
                        Thread.sleep(5);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            };
    
            putFile(inf, out);
    
            System.out.println("end");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }
    
    private static boolean putFile(String m_sLocalFile, OutputStream out /*FtpClient m_client*/) {
        boolean success = false;
        int BUFFER_SIZE = 10240;
        if (m_sLocalFile.length() == 0) {
            System.out.println("Please enter file name");
        }
        byte[] buffer = new byte[BUFFER_SIZE];
        try {
            File f = new File(m_sLocalFile);
            int size = (int) f.length();
            System.out.println("File " + m_sLocalFile + ": " + size + " bytes");
            System.out.println(size);
            FileInputStream in = new FileInputStream(m_sLocalFile);
            //test
            InputStream inputStream = new BufferedInputStream(
                          new ProgressMonitorInputStream(null,"Uploading " + f.getName(),in));
    
            //test
            //OutputStream out = m_client.put(f.getName());
    
            int counter = 0;
            while (true) {
                int bytes = inputStream.read(buffer);  //in
                if (bytes < 0)
                    break;
                out.write(buffer, 0, bytes);
                counter += bytes;
                System.out.println(counter);
            }
    
            out.close();
            in.close();
            inputStream.close();
            success =true;
        } catch (Exception ex) {
            System.out.println("Error: " + ex.toString());
        }
        return true;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anybody see what's wrong with my code? It behaves properly in IE but
Can anybody see where I am going wrong with this? I am trying to
Does anybody see anything wrong with the following function? ( Edit : no, I
Can anybody know how to remove all the indexes from database ?
I've read most of the relevant answers on this topic already, but I can't
I've read the FAQ and several other websites about this, but I can't seem
Why does php say me 'DEP $925'==0.0 is true? Can anybody point me to
I'm saving the location of my application but it does not want to keep
Hi all I have seen all question related to this problem but couldn't find
First off my apologies for how disgusting this code is, it is not my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.