Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Speichern von Textdateien

Empfohlene Antworten

Veröffentlicht

Ich will den Text aus einer Textarea in einer Datei speichern. Mein Code sieht zur Zeit wiefolgt aus:


FileDialog DateiDialog= new FileDialog(this,"Datei speichern",FileDialog.SAVE);
DateiDialog.setVisible(true);
datei= new File(DateiDialog.getFile());
try {
FileOutputStream dateiinhalt = new FileOutputStream(datei);
System.out.println(txtInhalt.getText() + "\n");
ObjectOutputStream output = new ObjectOutputStream(dateiinhalt);
output.writeObject(txtInhalt.getText());
txtInhalt.setText("");
//dateiinhalt.close();
}
catch (FileNotFoundException FNFExc) {
txtInhalt.setText("Datei konte nicht gespeichert werden!\n\n");
}
catch (IOException IOExc) {
txtInhalt.append("Fehler beim Schreiben der Datei!\n\n");
}
[/PHP]

Mein Problem: der erste Teil der gespeichert sieht wie Steuerzeichen und scheint die erste Zeile meines Strings komplett zu überschreiben. Wie kann ich das vermeiden?

Ausgabe am Anfang der eingelesenen Datei:

[CODE]’[/CODE]

Versuch mal:

try {
FileOutputStream dateiinhalt = new FileOutputStream(datei);
dateiinhalt.write(txtInhalt.getText().getBytes());
txtInhalt.setText("");
dateiinhalt.close();
} catch ... [/PHP]

MfG

Dalton

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.