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 9022595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:33:07+00:00 2026-06-16T05:33:07+00:00

I have the following method to determine the file size: public static long getSize(String

  • 0

I have the following method to determine the file size:

    public static long getSize(String path) {

    File file = new File(path);

    if (file.exists()) {
        long size = file.length();

        return size;
    } else {
        Log.e("zero size", "the file size is zero!");
        return 0;

    }

Now I want to show a dialog with the following method (the code IS NOT complete):

 public void gimmeDialog(String path_to_file) {

    final Dialog dialog = new Dialog(this);
    dialog.setContentView(R.layout.dialog);
    dialog.setTitle("Confirm");

    TextView text = (TextView) dialog.findViewById(R.id.txtUploadInfo);

    Button dialogButtonOK = (Button) dialog.findViewById(R.id.btnDialogOK);

    long uploadSize = Send.getSize(path_to_file) / 1024 / 1024;

    text.setText("You are about to upload "
            + Long.toString(uploadSize)
            + " MB. You must accept the terms of service before you can proceed");

    dialogButtonOK.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            dialog.dismiss();
        }
    });

    dialog.show();
}

The problem is that uploadSize is always zero, though the method getSize() returns correct file size when called outside the dialog function. The given string path IS correct. What can be the reason?

P.S. Send is my class name

  • 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-16T05:33:08+00:00Added an answer on June 16, 2026 at 5:33 am

    You are making a integer division and if the numenator is smaller than the denominator the result is 0.

    Try with a double division:

    double uploadSize = 1.0 * Send.getSize(path_to_file) / 1024 / 1024;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following method: public static T ExecuteScalar<T>( string query, SqlConnection connection, params
I have the following method: public string Phase(string phase) { return Phase 1; }
I have the following method: namespace ListHelper { public class ListHelper<T> { public static
I have the following code: if (System.IO.File.Exists(htmlLocation)) { vEarthBrowser.ObjectForScripting = this; vEarthBrowser.Url = new
I have following method in wcf webenabled service Public Person AddPerson(Person p); As of
I have the following method, which takes in the name of a file as
I have written the following method to detemine whether file in question is formatted
I have the following Method: http_client=Net::HTTP.new(@uri.host,@uri.port) request=Net::HTTP::Post.new(@uri.request_uri) request.set_form_data(params) request.basic_auth(@user,@pass) result = http_client.request(request) # #
I have come up with the following method to determine is a database is
I have a file of the following format: warning-some txt path_to_file, <line_number> method name

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.