P
philips0815
Neues Mitglied
- 0
Hallo!
Ich habe das Problem das wenn ich etwas in eine Datei schreibe und diese dann auslese immer null vor dem ausgelesenen Text steht.
z.b. Eingabe >> Hallo Welt!
Ausgabe>> nullHallo Welt!
Wie das?
Danke!
Datei schreiben:
Datei lesen:
Ich habe das Problem das wenn ich etwas in eine Datei schreibe und diese dann auslese immer null vor dem ausgelesenen Text steht.
z.b. Eingabe >> Hallo Welt!
Ausgabe>> nullHallo Welt!
Wie das?
Danke!
Datei schreiben:
Code:
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]
[LEFT]try[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] {
[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]ipadresse[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]ipadr[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].getText().toString();
Log.[I]d[/I]([/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]TAG[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]ipadresse[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].toString());
FileOutputStream fos = openFileOutput([/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]filename[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], Context.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]MODE_PRIVATE[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
fos.write([/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]ipadresse[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].getBytes());
} [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]catch[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (FileNotFoundException e) {
Log.[I]d[/I]([/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]TAG[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"FileNotFound"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
e.printStackTrace();
} [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]catch[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (IOException e) {
Log.[I]d[/I]([/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]TAG[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"IOException"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
e.printStackTrace();[/LEFT]
}
[/SIZE]
Datei lesen:
Code:
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]
[LEFT]try[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] {
FileInputStream stream = openFileInput([/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]file[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]byte[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][] input = [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]byte[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][stream.available()];
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]while[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](stream.read(input) != -1){
[/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//if (!input.equals(null)){[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]inputstring[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] += [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] String(input);
}
[/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//}[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]stream.close();
[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]text[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].setText([/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]inputstring[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/LEFT]
Log.[I]d[/I]([/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]TAG[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]inputstring[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
[/SIZE]