zoukankan      html  css  js  c++  java
  • IO流,使用指定的码表读写字符。

    public class Demo_TransIO{

      public static void main(String[] args) throws UnsupportedEncodingException, FileNotFoundException,IOException{

        InputStreamReader isr = new InputStreamReader (new FileInputStream("utf-8.txt"),"utf-8");    //指定码表读字符

        OutputStreamWriter osw = new OutputStreamWriter (new FileOutputStream(GBK.txt"),"GBK");  //指定码表写字符

        int c;

        while(c = isr.read() != -1){

          osw.write(c);

        }

        isr.close();

        osw.close();

      }

    }

    比上面方法更高效的:

      public static void demo02() throws UnsupportedEncodingException, FileNotFoundException,IOException{

        BufferedReader br = new BufferedReader (new InputStreamReader (new FileInputStream("utf-8.txt"),"utf-8"));    //指定码表更高效的读字符

        BufferedWriter bw= new BufferedWriter (new OutputStreamWriter(new FileOutputStream(GBK.txt"),"GBK"));  //指定码表更高效的写字符

        int c;

        while(c = br .read() != -1){

          bw.write(c);

        }

        br .close();

        bw.close();

      }

     

  • 相关阅读:
    Tapestry5 Setup with HTML5 and jQuery
    CSS学习六:布局剖析
    CSS学习三:表格,表单,超链接和鼠标等。
    CSS+DIV实战
    一到关于c++继承和多态的题
    一道有关指针的题
    小程序,嘿嘿
    《犯罪心理》名言部分
    ethereal与wincap
    并发编程之:Lock
  • 原文地址:https://www.cnblogs.com/wangffeng293/p/13199078.html
Copyright © 2011-2022 走看看