2011-12-14 20 views

risposta

17

Prima leggi il file dalla scheda SD e quindi analizzare il file

Fase-1 Recuperare i dati da file dalla scheda SD. vedere tutorial

Step-2 Analizzare i dati. Vedere How to parse JSON String

codice di esempio

try { 

      File dir = Environment.getExternalStorageDirectory(); 
      File yourFile = new File(dir, "path/to/the/file/inside/the/sdcard.ext"); 
      FileInputStream stream = new FileInputStream(yourFile); 
      String jString = null; 
      try { 
       FileChannel fc = stream.getChannel(); 
       MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size()); 
       /* Instead of using default, pass in a decoder. */ 
       jString = Charset.defaultCharset().decode(bb).toString(); 
       } 
       finally { 
       stream.close(); 
       } 


        JSONObject jObject = new JSONObject(jString); 



     } catch (Exception e) {e.printStackTrace();} 
+0

Come per la documentazione di Android, si afferma che getChannel() è la memoria costoso saggio. C'è un modo per farlo senza usare i canali? –

+0

Anche se la configurazione dei file mappati può essere costosa, il guadagno complessivo (in velocità) rispetto allo I/O del flusso è significativo. –

+0

Grazie .... ha funzionato – Noman

Problemi correlati