helroz Posted February 13, 2011 Share Posted February 13, 2011 Bonjour @tous, Je travaille actuellement 2 projets sur lesquels, je télécharge des données en http, sur l'un des 2 projets, le téléchargement n'est pas une super solution (appli pour désimlocker). Du coup je pense mettre les fichiers dont j'ai besoin dans /res/raw/ mais je ne comprends absolument pas comment les récupérer. Si quelqu'un saurait m'éclairer sur ce point? En vous remerciant par avance Helroz Link to comment Share on other sites More sharing options...
chpil Posted February 14, 2011 Share Posted February 14, 2011 Utilise la méthode openRawResource de la classe Resources (dont tu peux récupérer une instance en appelant getResources depuis une Activity par ex.), qui te retournera un InputStream te permettant de récupérer le contenu de ta ressource Link to comment Share on other sites More sharing options...
helroz Posted February 14, 2011 Author Share Posted February 14, 2011 oki, merci pour l'info, j'y regarde des que j'ai un peu de temps libre ;) Link to comment Share on other sites More sharing options...
helroz Posted February 15, 2011 Author Share Posted February 15, 2011 c'est parfait, merci pour les infos, tout fonctionne parfaitement, j'ai plus qu'a re-coder mon appli pour utiliser les fichiers au lieu de l'internet ;) Encore merci :D Pour info si quelqu'un a besoin: InputStream myInput = this.getResources().openRawResource(R.raw.mon_fichier_raw); //mon fichier de sortie ici extrait sur la SD dans le répertoire download String outFileName = Environment.getExternalStorageDirectory() + "/download/mon_fichier_de_sortie"; OutputStream myOutput; try { myOutput = new FileOutputStream(outFileName); byte[] buffer = new byte[1024]; int length; while ((length = myInput.read(buffer))>0){ myOutput.write(buffer, 0, length); } myOutput.flush(); myOutput.close(); myInput.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.