Shortest way to open encoded file and readLine () in Java?

What is the shortest way to open a file for reading using the readLine () method and setting its encoding?

Is the next line correct and shortest?

BufferedReader reader = new BufferedReader( new InputStreamReader( new FileInputStream(myPath), myEncoding)); 
+6
source share
1 answer

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

+14
source

Source: https://habr.com/ru/post/905171/


All Articles