解決UTF-8文件檔,JAVA讀取第一個字出現亂碼是問號? 的問題


import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class ReadMyWeb {
public static void main(String[] args) throws IOException {

FileInputStream fr= new FileInputStream("nicode.txt");
InputStreamReader insr= new InputStreamReader(fr,"UTF-8");
InputStream input = System.in;
    byte[] b = new byte[1024];
    char[] cc = new char[1024];
    int len = 0;
    StringBuffer sb = new StringBuffer("");

//     while ((len = input.read(b)) != 2) {
//         System.out.println(len);
//         sb.append(new String(b, 0, len));
//     }
    while ((len = insr.read(cc,0,cc.length)) != -1) {
        System.out.println(len);
        sb.append(new String(cc, 0, cc.length));
    }
   
    input.close();
    insr.close();
    fr.close();
    System.out.println(sb.toString());
   
}
}




http://blog.csdn.net/jackpk/article/details/5702964/

http://blog.csdn.net/w770583069/article/details/49337229

留言

這個網誌中的熱門文章

Use Case Description(描述使用案例)

列出不重複的隨機亂數

子類別建構子super觀念