List of usage examples for java.nio.charset StandardCharsets UTF_8
Charset UTF_8
To view the source code for java.nio.charset StandardCharsets UTF_8.
Click Source Link
From source file:Main.java
public static void main(String[] args) throws Exception { System.out.println(StandardCharsets.UTF_8.name()); }
From source file:Main.java
public static void main(String[] args) throws Exception { Scanner scanner = new Scanner(new File("c:/text.txt"), StandardCharsets.UTF_8.name()); System.out.println(scanner.nextLine()); scanner.close();/* w w w . jav a 2s .c o m*/ }
From source file:Main.java
public static void main(String[] args) throws Exception { Scanner scanner = new Scanner(new FileInputStream("c:/text.txt"), StandardCharsets.UTF_8.name()); System.out.println(scanner.nextLine()); scanner.close();/*from w ww . j av a 2 s .c o m*/ }
From source file:Main.java
public static void main(String[] argv) throws Exception { BufferedReader reader = Files.newBufferedReader(Paths.get("a.bat"), StandardCharsets.UTF_8); //BufferedReader's lines methods returns a stream of all lines reader.lines().forEach(System.out::println); }
From source file:Main.java
public static void main(String[] args) throws Exception { Scanner scanner = new Scanner(FileSystems.getDefault().getPath("logs", "access.log"), StandardCharsets.UTF_8.name()); System.out.println(scanner.nextLine()); scanner.close();/* w w w. j a v a 2s. co m*/ }
From source file:Main.java
public static void main(String[] args) throws FileNotFoundException { Scanner scanner = new Scanner(new FileInputStream("c:/text.txt").getChannel(), StandardCharsets.UTF_8.name()); System.out.println(scanner.nextLine()); // change the radix of the scanner scanner.useRadix(32);/*from w w w. ja va2s . co m*/ // display the new radix System.out.println(scanner.radix()); scanner.close(); }
From source file:Main.java
public static void main(String[] args) { String s = "from java2s.com!"; try {// w w w .jav a 2s.com OutputStream os = new FileOutputStream("test.txt"); OutputStreamWriter writer = new OutputStreamWriter(os, java.nio.charset.StandardCharsets.UTF_8); FileInputStream in = new FileInputStream("test.txt"); writer.write(s, 0, 5); writer.flush(); for (int i = 0; i < 5; i++) { System.out.print((char) in.read()); } writer.close(); in.close(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < 100; i++) { sb.appendCodePoint(1064124);/*ww w . j a va 2s . c o m*/ } Charset cs = StandardCharsets.UTF_8; System.out.println(bytesRequiredToEncode(new String(sb), cs)); System.out.println(new String(sb).getBytes(cs).length); }
From source file:de.tum.i13.ConvertCsvToProtobuf.java
public static void main(String args[]) { try {/* w w w .j ava 2 s .c om*/ LineIterator it = FileUtils.lineIterator(new File("/Users/manit/Projects/sdcbenchmark/Dataset/debscsv"), "UTF-8"); FileOutputStream out = new FileOutputStream("/Users/manit/Projects/sdcbenchmark/Dataset/debsprotobuf", true); while (it.hasNext()) { String csvLine = (String) it.next(); byte[] csvLineBytes = csvLine.getBytes(); String line = new String(csvLineBytes, StandardCharsets.UTF_8); Debs2015Protos.Taxitrip.Builder builder = Debs2015Protos.Taxitrip.newBuilder(); String[] splitted = line.split(","); builder.setMedallion(splitted[0]); builder.setHackLicense(splitted[1]); builder.setPickupDatetime(splitted[2]); builder.setDropoffDatetime(splitted[3]); builder.setTripTimeInSecs(Integer.parseInt(splitted[4])); builder.setTripDistance(Float.parseFloat(splitted[5])); builder.setPickupLongitude(Float.parseFloat(splitted[6])); builder.setPickupLatitude(Float.parseFloat(splitted[7])); builder.setDropoffLongitude(Float.parseFloat(splitted[8])); builder.setDropoffLatitude(Float.parseFloat(splitted[9])); builder.setPaymentType(splitted[10]); builder.setFareAmount(Float.parseFloat(splitted[11])); builder.setSurcharge(Float.parseFloat(splitted[12])); builder.setMtaTax(Float.parseFloat(splitted[13])); builder.setTipAmount(Float.parseFloat(splitted[14])); builder.setTollsAmount(Float.parseFloat(splitted[15])); builder.setTotalAmount(Float.parseFloat(splitted[16])); builder.build().writeDelimitedTo(out); } out.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:io.druid.query.aggregation.datasketches.quantiles.GenerateTestData.java
public static void main(String[] args) throws Exception { Path buildPath = FileSystems.getDefault().getPath("doubles_build_data.tsv"); Path sketchPath = FileSystems.getDefault().getPath("doubles_sketch_data.tsv"); BufferedWriter buildData = Files.newBufferedWriter(buildPath, StandardCharsets.UTF_8); BufferedWriter sketchData = Files.newBufferedWriter(sketchPath, StandardCharsets.UTF_8); Random rand = new Random(); int sequenceNumber = 0; for (int i = 0; i < 20; i++) { int product = rand.nextInt(10); UpdateDoublesSketch sketch = UpdateDoublesSketch.builder().build(); for (int j = 0; j < 20; j++) { double value = rand.nextDouble(); buildData.write("2016010101"); buildData.write('\t'); buildData.write(Integer.toString(sequenceNumber)); // dimension with unique numbers for ingesting raw data buildData.write('\t'); buildData.write(Integer.toString(product)); // product dimension buildData.write('\t'); buildData.write(Double.toString(value)); buildData.newLine();/*from ww w.ja v a 2 s . c o m*/ sketch.update(value); sequenceNumber++; } sketchData.write("2016010101"); sketchData.write('\t'); sketchData.write(Integer.toString(product)); // product dimension sketchData.write('\t'); sketchData.write(Base64.encodeBase64String(sketch.toByteArray(true))); sketchData.newLine(); } buildData.close(); sketchData.close(); }