ตัวอย่าง
ในตัวอย่างเราใช้ DataInputStream เพื่อแปลงข้อมูลทั้งหมดเป็น bytes ก่อนจากนั้นสร้างตัวแปลของ String มารองรับพร้อมแปลง bytes เป็น String.
package demo.file; import java.io.DataInputStream; import java.io.FileInputStream; public class ContentIntoVariableExample { /** * @param args */ public static void main(String[] args) { try { DataInputStream dis = new DataInputStream(new FileInputStream( "C:\\users\\nopphanan7\\test.log")); byte[] datainBytes = new byte[dis.available()]; dis.readFully(datainBytes); dis.close(); String content = new String(datainBytes, 0, datainBytes.length); System.out.println(content); } catch (Exception ex) { ex.printStackTrace(); } } }ผลลัพธ์ที่ได้คือ
-----BEGIN RSA PRIVATE KEY----- MIIEoAIBAAKCAQEAwobsGqBNFHbDW5aJVCCsxK5Q43So+NcS3pX1guJ81J5Ae8ae bsYmRpHJdEs7vuiVPZy3mEd2pxk91bUKLofOeCLdqgmmckQX2AHXvU5zOfzLvjf/ MDGSecTMx5jvOKS+jGe3ybLtDU1jat0e+OX0IqwS9jKOyuOfwBcrZbXQ+1/phuI8 VP3KGoKHOS08G8wXqb3/OS4QuxpPmyCywBlTyKHCWHb4KGvpvE/AWSDZt2RhZAXw 71vYwp+LoqWNG0ESc7cfBFQHxEh1DPpfytWcR/+OrjQwR2Q0v/OEuM28XKwL1UOg k18JsNbLLE238W279jHPRi0iJp5FEHZemJKN3wIBIwKCAQA9IxcBDc8VD2H4NqAw YgppsyC8g8ATsU8SwWpq9rmEpsPPISp6lgwHjOeK8xLG+KPuytqdks2E+U3ytT22 2jmTeKwQ3nYj6YPWLHcA+2YK6QzVYg5fmo0e9LVjTVJ/hDvi/AaP2SXuPOS7L41k KwOV3k8aLSWQOOkQfE93vMymxdLdwf6bAfI8TAbDv8VXQErJFTL4WUlf/ch3bbmb 40AlYhAdLwmD/yfc/69MNz7b65pm8Dw7v+0/tUk41WlW6XDHeH3AOLkJadndehlL YuErx7nCyDqbmZl9/7AGpEuURwPfXrIDvVZ0hy87NM98PzEj6Lsa/bsI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