Java Files read text by Charset

Description

Java Files read text by Charset


import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;

public class Main {

  public static void main(String[] args) throws Exception{
    String path = "Main.java";
    List<String> lines = Files.readAllLines(Paths.get(path), Charset.forName("US-ASCII"));
    //List<String> lines = Files.readAllLines(Paths.get(path), Charset.forName("ISO-8859-1"));
    //List<String> lines = Files.readAllLines(Paths.get(path), Charset.forName("UTF-8"));
    //List<String> lines = Files.readAllLines(Paths.get(path), Charset.forName("UTF-16BE"));
    //List<String> lines = Files.readAllLines(Paths.get(path), Charset.forName("UTF-16LE"));
    //List<String> lines = Files.readAllLines(Paths.get(path), Charset.forName("UTF-16"));
    for (String s : lines) {
        System.out.println(s);/*w  w w.  jav  a2 s.com*/
    }
    
  }
}



PreviousNext

Related