You are not logged in.

  • Login

1

Friday, March 14th 2008, 12:09pm

Zeilenweise aus Dateien lesen?

Hallo,
ich müsste zeilenweise aus Dateien lesen. Dazu habe ich die Funktion readline() eines DataInputStream's gefunden.
Allerdings gibts beim kompilieren die Warnung:

Source code

1
Warning(247,36): method readLine() has been deprecated

Gibts denn eine andere Möglichkeit, aus einer Datei zu lesen, außer jedes Zeichen einzeln?
Zeilenweise hätte den Vorteil, dass ich einfacher mit regulären Ausdrücken suchen und auswerten kann...

Danke

2

Friday, March 14th 2008, 12:12pm

Guck einfach mal in die API: http://java.sun.com/javase/6/docs/api/

Da kannste bei der entsprechenden Klasse alles ablesen, was du wissen möchtest: http://java.sun.com/javase/6/docs/api/ja…m.html#readLine()

In deinem Fall:

Quoted

readLine

@Deprecated
public final String readLine()
throws IOException

Deprecated. This method does not properly convert bytes to characters. As of JDK 1.1, the preferred way to read lines of text is via the BufferedReader.readLine() method. Programs that use the DataInputStream class to read lines can be converted to use the BufferedReader class by replacing code of the form:

DataInputStream d = new DataInputStream(in);


with:

BufferedReader d
= new BufferedReader(new InputStreamReader(in));


See the general contract of the readLine method of DataInput.

Bytes for this operation are read from the contained input stream.

Specified by:
readLine in interface DataInput

Returns:
the next line of text from this input stream.
Throws:
IOException - if an I/O error occurs.
See Also:
BufferedReader.readLine(), FilterInputStream.in


3

Friday, March 14th 2008, 12:22pm

Ah, danke.

Mir fällt gerade auf, dass ich auch einfach bis zum Zeilen-Ende alle Zeichen einlesen hätte können und dann auswerten. :rolleyes:
Naja, ich versuchs mal.

Similar threads

Social bookmarks