J
JoEW
Neues Mitglied
- 0
Hallo Leute,
ich finde leider keinen passenden Beitrag für meinen Fehler. Ich wollte Dateioperationen ausprobieren und habe mich an der Developer Seite von android orientiert. Der folgende Code läuft auch ohne Fehlermeldung. Allerdings ist die Rückmeldung (Toast) nach dem Laden der gerade gespeicherten Daten für mich doch recht überraschend. Statt des Inhaltes wird der Dateiname angegeben.
private
ich finde leider keinen passenden Beitrag für meinen Fehler. Ich wollte Dateioperationen ausprobieren und habe mich an der Developer Seite von android orientiert. Der folgende Code läuft auch ohne Fehlermeldung. Allerdings ist die Rückmeldung (Toast) nach dem Laden der gerade gespeicherten Daten für mich doch recht überraschend. Statt des Inhaltes wird der Dateiname angegeben.
private
void PoIspeichern() {
Vielen Dank für eure Hilfe!
JoEW
try{
String FILENAME = "meintest.txt";
String string = "info 1";
String string2 = "info 2";
String string3 = "info 3";
FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
fos.write(string.getBytes());
fos.write(string2.getBytes());
fos.write(string3.getBytes());
fos.close();
}
catch(IOException e){
Context context = getApplicationContext();
CharSequence text = "Fehler beim Schreiben!";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
String FILENAME = "meintest.txt";
String string = "info 1";
String string2 = "info 2";
String string3 = "info 3";
FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
fos.write(string.getBytes());
fos.write(string2.getBytes());
fos.write(string3.getBytes());
fos.close();
}
catch(IOException e){
Context context = getApplicationContext();
CharSequence text = "Fehler beim Schreiben!";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
}
privatevoid PoIladen() {
try{
String gtext = "";
String strLine;
String FILENAME = "meintest.txt";
try{
String gtext = "";
String strLine;
String FILENAME = "meintest.txt";
FileInputStream fis = new FileInputStream(FILENAME);
BufferedInputStream bis = new BufferedInputStream(fis);
DataInputStream dis = new DataInputStream(bis);
BufferedInputStream bis = new BufferedInputStream(fis);
DataInputStream dis = new DataInputStream(bis);
while (dis.available() != 0) {
strLine = dis.readLine();
gtext = gtext + strLine;
}
strLine = dis.readLine();
gtext = gtext + strLine;
}
fis.close();
bis.close();
dis.close();
bis.close();
dis.close();
Context context = getApplicationContext();
CharSequence text = gtext;
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
catch (IOException e){
Context context = getApplicationContext();
CharSequence text = e.getMessage();
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
CharSequence text = gtext;
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
catch (IOException e){
Context context = getApplicationContext();
CharSequence text = e.getMessage();
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
}Vielen Dank für eure Hilfe!
JoEW