

Android - Java uložení a přečtení hodnot ze souboru
Ahoj,
mám jednoduchou potíž. Chci uložit do souboru hodnoty a tyto potom přečíst (řádek po řádku).
Uložení:
// zapsani:
writeNameToFile("prvni radek \r\n"+"druhy radek" , context);
private void writeNameToFile(String data,Context context) {
try {
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(context.openFileOutput("soubor.txt", Context.MODE_PRIVATE));
outputStreamWriter.write(data);
outputStreamWriter.close();
}
catch (IOException e) {
MessageBox("Exception File write failed: " + e.toString());
}
}
Načtení:
InputStream inputStream = tatoaktivita.openFileInput("soubor.txt");
Boolean poprve = true;
if ( inputStream != null ) {
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
String receiveString = "";
StringBuilder stringBuilder = new StringBuilder();
while ( (receiveString = bufferedReader.readLine()) != null ) {
if(poprve){
poprve = false;
Toast.makeText(getApplicationContext(),"prvni radek:"+ receiveString , Toast.LENGTH_LONG).show();
}else
{
Toast.makeText(getApplicationContext(),"druhy radek:" receiveString , Toast.LENGTH_LONG).show();
}
}
inputStream.close();
}
}
catch (FileNotFoundException e) {
MessageBox("login activity File not found: " + e.toString());
} catch (IOException e) {
MessageBox("login activity Can not read file: " + e.toString());
}
Ovšem při načtení se vůbec nezobrazují načtené řádky.
V čem to může být? V Contextu?