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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:25:31+00:00 2026-06-04T17:25:31+00:00

I am trying to write the class to download the file from server and

  • 0

I am trying to write the class to download the file from server and store it on sd card.But I am getting one Exception as java.io.FileNotFoundException: /mnt/sdcard/files.zip (No such file or directory).

My Main class is

public class DownloadZipActivity extends Activity {
    /** Called when the activity is first created. */
    int count;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        try {

        URL url = new URL(
                "url to download");

       /*   URLConnection conexion = url.openConnection();
        conexion.connect();
*/
            HttpURLConnection conn = (HttpURLConnection)url.openConnection();
            conn.setDoInput(true);
            conn.setConnectTimeout(1000); // timeout 10 secs
            conn.connect();

        int lenghtOfFile = conn.getContentLength();
        Log.d("ANDRO_ASYNC", "Lenght of file: " + lenghtOfFile);

        InputStream input = new BufferedInputStream(url.openStream());
        OutputStream output = new FileOutputStream("/mnt/sdcard/external_sd/files.zip");

        byte data[] = new byte[1024];

        long total = 0;

            while ((count = input.read(data)) != -1) {
                total += count;
        //      publishProgress(""+(int)((total*100)/lenghtOfFile));

                    output.write(data, 0, count);
                }


            output.flush();
            output.close();
            input.close();
        } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

        String zipFile = Environment.getExternalStorageDirectory() + "/files.zip"; 
        String unzipLocation = Environment.getExternalStorageDirectory() + "/unzipped/"; 
        Decompress d = new Decompress(zipFile, unzipLocation); 
        d.unzip(); 
    }
}

and decompress class is

public class Decompress {
     String _zipFile; 
      String _location; 
    public Decompress(String zipFile, String unzipLocation) {

        // TODO Auto-generated constructor stub
        _zipFile = zipFile; 
        _location = unzipLocation; 

        _dirChecker(""); 
    }
    public void unzip() { 
        try  { 
          FileInputStream fin = new FileInputStream(_zipFile); 
          ZipInputStream zin = new ZipInputStream(fin); 
          ZipEntry ze = null; 
          while ((ze = zin.getNextEntry()) != null) { 
            Log.v("Decompress", "Unzipping " + ze.getName()); 

            if(ze.isDirectory()) { 
              _dirChecker(ze.getName()); 
            } else { 
              FileOutputStream fout = new FileOutputStream(_location + ze.getName()); 
              for (int c = zin.read(); c != -1; c = zin.read()) { 
                fout.write(c); 
              } 

              zin.closeEntry(); 
              fout.close(); 
            } 

          } 
          zin.close(); 
        } catch(Exception e) { 
          Log.e("Decompress", "unzip", e); 
        } 

      } 

      private void _dirChecker(String dir) { 
        File f = new File(_location + dir); 

        if(!f.isDirectory()) { 
          f.mkdirs(); 
        } 
      } 
}
  • 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-04T17:25:32+00:00Added an answer on June 4, 2026 at 5:25 pm

    Carefully look at your code

    When downloading and saving file you are saving it in following path

    OutputStream output = new FileOutputStream("/mnt/sdcard/external_sd/files.zip");
    

    But while reading you are referring following path

    String zipFile = Environment.getExternalStorageDirectory() + "/files.zip"; 
    

    which is equivalent to

    String zipFile = "/mnt/sdcard/files.zip"; 
    

    You should write

    String zipFile = Environment.getExternalStorageDirectory() + "/external_sd/files.zip";
    

    Hope this helps

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my application, I'm trying to download a file from my website, but I'm
Im trying to download and save a file from a HttpWebResponse but im having
I am trying download zip file to SD card. I download it correctly, but
I'm trying to write a class in C++, but whenever I try to compile,
I am trying to write a logger class for my C++ calculator, but I'm
I am trying to write a template class in C++ and getting this strange
I'm trying to write a Java class to log in to a certain website.
I am trying to write a java program that will automatically download and name
I am trying to download a file from a URL. If the download fails
I am trying to write a class library and I am getting the following

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.