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.

Datenstream

Empfohlene Antworten

Veröffentlicht

Hallo,

ich hab ein Problem beim einlesen einer Textdatei. Ich will sie einlesen und den Inhalt in einer TextArea anzeigen. Das Problem ist das ich die Datei zwar einlesen kann aber es wird immer nur die letzte Zeile angezeigt.

Vielleicht kann mir jemand helfen.

Mal alles was mit dem Stream zu tun hat.

----------------------------------------------------

JTextArea Text = new JTextArea ("", 1, 1);

String S;

Panel1.add("Center",Text);

Text.setEditable(false);

public void actionPerformed (ActionEvent e) {

Object source = e.getSource();

if(source == MenuItem1) {

Text.setText("Neu");

}

if(source == MenuItem2) {

try {

BufferedReader file_in = new BufferedReader (new InputStreamReader (new FileInputStream("Filme.txt")));

while( (S = file_in.readLine()) != null) {

Text.setText(S);

}

file_in.close();

}

catch(IOException ioe){

ioe.printStackTrace();

}

}

if(source == MenuItem3) {

Text.setText("Speichern");

}

if(source == MenuItem4) {

System.exit(0);

}

}

public static void main(String args[]){

JFilmeVerwalter test = new JFilmeVerwalter();

test.fenster();

}

}

Hi,

verwende statt setText() mal append(); das muesste gehen. ;)

so long

Danke für deine schnelle Antwort. Es funktioniert jetzt zwar, aber jetzt gibt er alles in einer Zeile aus. Ich will aber das er die Zeilen beibehält.

JTextArea.append(BufferedReader.readLine() + "\r");

oder

JTextArea.append(BufferedReader.readLine() + "\n");

muesste gehen. ;)

Danke. Noch ein Stück weiter :D

Mit Text.append(file_in.readLine() + "\r"); geht es nicht.

aber mit Text.append(file_in.readLine() + "\n");

jetzt is aber das Problem das immer nur jede 2.te Zeile ausgegeben wird. Und am Schluß null steht ?

und "\n\r" ?

ne geht immer noch nicht ...

immer nur die 2.te Zeile ??

hat vielleicht jemand ne andere Lösung ?

ahhhhhhhhhhhh .......... "peinlich" ...

hab die "Lösung" ... hab

while( (S = file_in.readLine()) != null) {

Text.append(file_in.readLine() + "\n\r");

gemacht ... aber

while( (S = file_in.readLine()) != null) {

Text.append(S + "\n\r");

gehörts sich. SORRY

Aber jetzt weis ich wenigstens wie man nur jede zweite Zeile ausliest ;D

Hm vielleicht kann mir ja noch jemand mit dem Speicher einer Datei helfen.

Hab mal so ins blaue getippt (bin absoluter Neuling) und diese Methode geschrieben.

Ok is schon *******e aber vielleicht kann mich ja jemand verbessern :D

___________________________________

public void speichern () {

try {

PrintWriter file_out = new PrintWriter (new OutputStreamWriter (new FileOutputStream("Filme.txt")));

while( (S = file_out.readLine()) != null) {

file_out.write("Filme.txt");

}

file_out.close();

}

catch(IOException ioe){

ioe.printStackTrace();

}

}

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.