Java Files create BufferedReader for ISO-8859-1 Charset

Description

Java Files create BufferedReader for ISO-8859-1 Charset

import java.io.BufferedReader;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class Main {

   public static void main(String[] args) {
      Path path = Paths.get("Main.java");
      Charset charset = Charset.forName("ISO-8859-1");
      try (BufferedReader reader = Files.newBufferedReader(path, charset)) {
         String line = null;/*  w w  w .  j a va2  s.co  m*/
         while ((line = reader.readLine()) != null) {
            System.out.println(line);
         }
      }catch(Exception e) {
         e.printStackTrace();
      }
   }
}



PreviousNext

Related