Note that there are some explanatory texts on larger screens.

plurals
  1. PODownloading pdf file and saving to SD card
    primarykey
    data
    text
    <p>I want to download and save pdf file to internal storage. Here is code that i am using:</p> <p>I am calling my method from other class:</p> <pre><code>new Thread(new Runnable() { public void run() { new Main().downloadPdfContent("http://people.opera.com/howcome/2005/ala/sample.pdf"); } }).start(); </code></pre> <p>Method look like this:</p> <pre><code>public void downloadPdfContent(String urlToDownload){ URLConnection urlConnection = null; try{ URL url = new URL(urlToDownload); //Opening connection of currrent url urlConnection = url.openConnection(); urlConnection.connect(); //int lenghtOfFile = urlConnection.getContentLength(); String PATH = Environment.getExternalStorageDirectory() + "/1/"; File file = new File(PATH); file.mkdirs(); File outputFile = new File(file, "test.pdf"); FileOutputStream fos = new FileOutputStream(outputFile); InputStream is = url.openStream(); byte[] buffer = new byte[1024]; int len1 = 0; while ((len1 = is.read(buffer)) != -1) { fos.write(buffer, 0, len1); } fos.close(); is.close(); System.out.println("--pdf downloaded--ok--"+urlToDownload); }catch (Exception e) { // TODO: handle exception e.printStackTrace(); } } </code></pre> <p>I found link of pdf on the web: <a href="http://people.opera.com/howcome/2005/ala/sample.pdf" rel="nofollow">http://people.opera.com/howcome/2005/ala/sample.pdf</a></p> <p>However i get an exception on this line:</p> <p><strong>urlConnection.connect();</strong></p> <p>Exception: <strong>java.net.UnknownHostException: people.opera.com</strong></p> <p>I can't figure out what's wrong. Maybe someone could take a look. </p> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload