Originariamente inviato da
solutiong
Ciao a tutti ho letto un po in giro come leggere da un file di testo tutti usano la stessa procedura ma a me non funziona.
io faccio così
public void leggi_scrivi(){
//Get the text file
File sdcard = Environment.getExternalStorageDirectory();
File file = new File(sdcard,"/crea.txt");
String id,nome,cognome,elemento;
String[] item;
String[] item2;
InputStream is;
try {
BufferedReader br = new BufferedReader(new FileReader(file));
String line;
while ((line = br.readLine()) != null) {
item = line.split("\\;");
id=item[0];
nome=item[1];
cognome=item[2];
Toast.makeText(Home.this,id+nome+cognome, Toast.LENGTH_SHORT ).show();
}
}
catch (IOException e) {
//You'll need to add proper error handling here
Toast.makeText(Home.this,e.toString(), Toast.LENGTH_SHORT ).show();
}
//Find the view by its id
}
e mi trova sempre il buffer vuoto mentre il file è così composto
1;andrea;via 1 maggio
2;rosanna;via 3 giugno
3;alberto;via 25 aprile