Reading a text file in java [closed]

Try the Scanner class which no one knows about but can do almost anything with text.

To get a reader for a file, use

File file = new File ("...path...");
String encoding = "...."; // Encoding of your file
Reader reader = new BufferedReader (new InputStreamReader (
    new FileInputStream (file), encoding));

... use reader ...

reader.close ();

You should really specify the encoding or else you will get strange results when you encounter umlauts, Unicode and the like.

Leave a Comment