passing pdf from assets to sdcard
<p>i'm trying to pass on sdcard a pdf from my raw folder to open it with a default intent.</p>

<p>When I open it, it's said to me that the pdf is dammaged. since I don't quite understants how stream works, I think that the issue comes frome there.</p>

<pre><code>final String extStorageDirectory = Environment
                        .getExternalStorageDirectory().toString();
                final String festivalDirectory_path = extStorageDirectory
                        + Constants.PDF_STORAGE_PATH;
                File pdfOutputFile = new File(festivalDirectory_path, "/");
                if (pdfOutputFile.exists() == false) {
                    pdfOutputFile.mkdirs();
                }
                File pdfFile = new File(pdfOutputFile, nameOfThePdf);

                try {
                    InputStream in = getResources().openRawResource(R.raw.blablublo);

                    FileOutputStream out = new FileOutputStream(pdfFile);
                    byte[] buffer = new byte[1024];
                    int bufferLength = 0;
                    while ((bufferLength = in.read(buffer)) &gt; 0) {
                        out.write(buffer, 0, bufferLength);
                    }
                    out.close();
                } catch (Exception e) {
                    Log.e("tag", e.getMessage());
                }
                Uri path = Uri.fromFile(pdfFile);
//              Uri path = Uri.parse(Constants.SPLASH_URI + R.raw.cartecannotpdf);
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setDataAndType(path, "application/pdf");
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);
</code></pre>

<p>Hope that someone could help me !</p>

<p>thx</p>

<p>Renaud</p>
