Android: Comment lire un fichier en octets?

J’essaie d’obtenir le contenu du fichier en octets dans une application Android. J’ai maintenant le fichier dans la carte SD et je veux maintenant obtenir le fichier sélectionné en octets. J’ai googlé mais pas un tel succès. S’il vous plaît aider

Voici le code pour obtenir des fichiers avec extension. Grâce à cela, je reçois des fichiers et montre en spinner. Lors de la sélection du fichier, je veux obtenir un fichier en octets.

private List getListOfFiles(Ssortingng path) { File files = new File(path); FileFilter filter = new FileFilter() { private final List exts = Arrays.asList("jpeg", "jpg", "png", "bmp", "gif","mp3"); public boolean accept(File pathname) { Ssortingng ext; Ssortingng path = pathname.getPath(); ext = path.subssortingng(path.lastIndexOf(".") + 1); return exts.contains(ext); } }; final File [] filesFound = files.listFiles(filter); List list = new ArrayList(); if (filesFound != null && filesFound.length > 0) { for (File file : filesFound) { list.add(file.getName()); } } return list; } 

ici c’est simple:

 File file = new File(path); int size = (int) file.length(); byte[] bytes = new byte[size]; try { BufferedInputStream buf = new BufferedInputStream(new FileInputStream(file)); buf.read(bytes, 0, bytes.length); buf.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } 

Ajouter une autorisation dans manifest.xml: