Android: Unable to download file from Server (FileNotFoundException)

Android: Unable to download file from Server (FileNotFoundException)

By : user2951614
Date : November 18 2020, 11:13 AM
With these it helps I was trying to download file from Server. Code as follows: , Try this simple example:
code :
import java.io.BufferedInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;

import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class download extends Activity {

    public static final int DIALOG_DOWNLOAD_PROGRESS = 0;
    private Button startBtn;
    private ProgressDialog mProgressDialog;

    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {
        startBtn = (Button)findViewById(R.id.startBtn);
        startBtn.setOnClickListener(new OnClickListener(){
            public void onClick(View v) {

    private void startDownload() {
        String url = "http://yoursite"; //your download url
        new DownloadFileAsync().execute(url);
    protected Dialog onCreateDialog(int id) {
        switch (id) {
            mProgressDialog = new ProgressDialog(this);
            mProgressDialog.setMessage("Downloading file..");
            return mProgressDialog;
            return null;

class DownloadFileAsync extends AsyncTask<String, String, String> {

    protected void onPreExecute() {

    protected String doInBackground(String... aurl) {
        int count;

    try {

    URL url = new URL(aurl[0]);
    URLConnection conexion = url.openConnection();

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

    InputStream input = new BufferedInputStream(url.openStream());
    OutputStream output = new FileOutputStream("/sdcard/YOURFLIENAME.XLS"); //save file in SD Card

    byte data[] = new byte[1024];

    long total = 0;

        while ((count = input.read(data)) != -1) {
            total += count;
            output.write(data, 0, count);

    } catch (Exception e) {}
    return null;

    protected void onProgressUpdate(String... progress) {

    protected void onPostExecute(String unused) {
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>

Share : facebook icon twitter icon
Unable to show Download Progress of File from New Server (worked on previous server)

Unable to show Download Progress of File from New Server (worked on previous server)

By : user3088224
Date : March 29 2020, 07:55 AM
it should still fix some issue Just posting the result as an answer so I can mark the question as answered. to all for the helpful comments!
I found a forum on the hosting provider's website where someone explained that gzip has recently been turned on, and detailed how to stop it. http://www.bluehostforum.com/showthread.php?18996-Turning-off-Gzip
code :
SetEnv no-gzip dont-vary
Android: Unable to download file from Server

Android: Unable to download file from Server

By : user2951542
Date : November 18 2020, 11:13 AM
it helps some times This exception is thrown when an application attempts to perform a networking operation on its main thread. Run your code in AsyncTask:
code :
class downloadFile extends AsyncTask<Void, Void, Void>

        protected Void doInBackground(Void... params) 
            downloadFile(file_url_list[position], "aaa");
            return null;


new downloadFile().execute();

<uses-permission android:name="android.permission.INTERNET"/>
Unable to download txt file from ftp server in Android

Unable to download txt file from ftp server in Android

By : Reza Samet
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further It sounds like you don't have the right directory or file location at the server level.
E/BitmapFactory: Unable to decode stream: java.io.FileNotFoundException: Download/my_file.JPEG (No such file or director

E/BitmapFactory: Unable to decode stream: java.io.FileNotFoundException: Download/my_file.JPEG (No such file or director

By : user3434711
Date : March 29 2020, 07:55 AM
Any of those help I have tried every single way, but I haven't got output. It is showing an error I have tried various way.
code :
 File imgFile = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);

        Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getPath() + "/my_file.JPEG");
    else {
Unable to download the file from local server to android emulator

Unable to download the file from local server to android emulator

By : Luís Fernando Sant'A
Date : March 29 2020, 07:55 AM
this one helps. I am trying to download the data from the local server on my emulator but I am not getting getting the data. How can this task be completed , you should change the url to :
Related Posts Related Posts :
  • Android Studio gradle build failed for hello world app
  • Slide a layout up from bottom of screen
  • Play HTML5 video in iOS/Android native media player
  • How to rescale a bitmap file in android?
  • No view found for id 0x for fragment after rotation?
  • Define different themable styles to the same widget types
  • ProGuard not working in my app
  • FragmentTransaction from BaseAdapter
  • Connecting multiple devices in a Wifi Direct group
  • Why TabActivity is deprecated in android
  • How to capture low resolution picture using android camera
  • android preferenceactivity padding in landscape orientation
  • How can I store cookie in webview?
  • Passing variables from one activity to another
  • Create Multicolored Pie Chart in Android Studio
  • how to kill progress dialog in android
  • Show Error on the tip of the Edit Text Android
  • How do I use getWindowManager() by another java file
  • fetching images from gallery on android phones with internal storage
  • How to discover devices like Google TV and Nexus-Q using MediaRoute API on Android?
  • "Unfortunately your app stopped working"- Facebook Integration for Android
  • How to animate button in android?
  • Resource Not Found Exception in class without context or activity
  • Launching Android Netflix App And Passing Video Id
  • Making a Phone Call with a Number Extension
  • NullPointerException at BoringLayout.isBoring is anything but boring
  • java.lang.RuntimeException: Unable to get provider
  • Testing custom Views with Robolectric
  • tools:listheader doesn't work although tools:listitem does
  • oppo, vivo app kill notification not coming in android fcm
  • OnClick Method could not function correctly with if else statement
  • Best method to download image from url in Android
  • How can I open Drawer Layout moving all the view and not just slide over?
  • how to show profile pictures of friends in a list view?
  • Creating TimePickerDialog with custom style in Android
  • Android 2.3.6 support library v7 option menu is missing
  • need of vblank in Display subssytem
  • Android MP4 stream - Video cannot be played
  • FastAdapter: Undo button does not show up after swipe
  • What are reasons to pass getActivity as the LifecycleOwner to the LiveData's observe method in a fragment?
  • Implement Face Recognition in Android
  • Titanium studio cannot run "titanium" command in terminal
  • How to execute command line ffmpeg commands programatically in android?
  • Make Android List Items clickable with each item pointing to a different link
  • listview runs successfully, but nothing is display in emulator
  • How to zoom in a bitmap with high resolution?
  • Passing listView data through intent
  • Google map route direction show by arrows in android v2
  • how to start "uiautomator test run" from android code?
  • Proguard in Android Library
  • Alarm Clock from GIT - Gives error - Android
  • Mock injection using Mockito - Android
  • Get Bitmap from universal image loader
  • Unable to include custom font in android
  • Basics on using logcat in Android development
  • Android: Clear cache programmatically
  • Android: pass object without serialization
  • Can not scroll and click item on gridview inside scrollview
  • Android device keeps disconnecting from adb / eclipse
  • Volley cannot create cache directory. Could not clean up file
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org