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.

Empfohlene Antworten

Veröffentlicht

Ich habe eine Frage. Warum macht mein Programm keinen Zeilenumbruch, wenn es in eine andere Datei schreibt? Sie schreibt anstatt dem Zeilenumbruch(\n) ein [] hin. Kann mir da bitte wer helfen?


import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.io.*;

public class Entfernen implements ActionListener
{
String m = "0";
String h = "1";
String er = "2";
String wert = "";
String beschreibung = "";
static Vector entf = new Vector();
String tre = " [,]= [,]";
String stri;

public void actionPerformed(ActionEvent e)
{
String inhalt = "" + PropertyGui.auswahlcmb.getSelectedIndex();

if (inhalt.equals(m))
{
System.out.println("MODUS");
System.out.println(Tabelle.vrowData);
System.out.println(Tabelle.table.getSelectedRow());
int i = Tabelle.table.getSelectedRow();
System.out.println(i);
Tabelle.vrowData.remove(Tabelle.vrowData.get(i));
System.out.println(Tabelle.vrowData);

String f = "testmodus.txt";
Enumeration enum = Tabelle.vrowData.elements();

while(enum.hasMoreElements())
{
String au = "" + enum.nextElement();

StringTokenizer st = new StringTokenizer(au,tre);
while (st.hasMoreTokens())
{
stri = "" + st.nextToken() + "=" + st.nextToken() + "\n";
}

try
{
RandomAccessFile output = new RandomAccessFile("testmodus.txt","rw");
output.seek(output.length());
output.write(stri.getBytes());
}
catch(IOException ioe)
{
System.err.println(ioe.getMessage());
}
}
}
else
{
if (inhalt.equals(h))
{
}
else
{
if (inhalt.equals(er))
{
}
else
{
System.out.println("Es wurde keine Datei gefunden");
}
}
}
}
}
[/PHP]

Hallo,

output.write(stri.getBytes());

output.newLine();

\n geht nicht, da der Zeilenumbruch betriebssystemabhängig ist.

Unter Win32 erreicht man ein newline mit \r\n

Alleiniges \n wird bei Unix verwendet und \r bei Macintosh.

Deswegen sollte man immer mit newLine() arbeiten, da das die system

property line.separator berücksichtigt.

Gruß Jaraz

Wenn du die erstellte Datei im Notepad geöffnet hast, dann benutze mal das Wordpad, manchmal hat das Notepad einfach Probleme mit Formatierungen.

Ansonsten kannst du noch \r probieren, vielleicht geht das ja...

output.newLine();

funktioniert leider nicht

Jau, hast recht. Die Methode gibt es nur bei nem BufferedWriter.

Dann hole dir den Seperator mit System.getProperty("line.separator");

und schreibe den dann so wie deine Strings.

Gruß Jaraz

Servus!!

Müsste es nicht auch gehen, wenn er das \n nicht in " " sondern in ' ' setzt? So wie es jetzt ist, wird das ganze ja als String interpretiert. Es soll aber doch als Zeichen gewertet werden.

Ist dann halt plattformabhängig.

k.o.b

Hy,

gibt es da nicht was mit .writeLine() oder so??

Gruß aokieh

  • 17 Jahre später...
  • Gast hat dies Thema gesperrt
Gast
Dieses Thema ist für weitere Antworten geschlossen.

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.