6

What is the shortest way to open file for reading with readLine() method and with setting of it's encoding?

Is the following line correct and shortest?

BufferedReader reader = 
    new BufferedReader(
         new InputStreamReader(
             new FileInputStream(myPath), myEncoding));
Dims
  • 47,675
  • 117
  • 331
  • 600

1 Answers1

14

With Scanner, you can do: Scanner scan = new Scanner(new File(myPath), myEncoding) and then scan.nextLine() which returns a String.

Bart Kiers
  • 166,582
  • 36
  • 299
  • 288