zoukankan      html  css  js  c++  java
  • 定义Java类实现字节流转字符流

    package com.buaa.comparable;

    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.Reader;
    import java.io.StringReader;
    import java.io.UnsupportedEncodingException;

    public class TestRead {

    /*static void parse(char[] c,String str){
    str = str.copyValueOf(c);
    try {
    str = new String(str.getBytes("gbk"),"utf-8");
    } catch (UnsupportedEncodingException e) {
    e.printStackTrace();
    }
    }*/
    public static void main(String[] args) {
    testReader();

    }
    static void testReader(){
    File f = new File("d:/a.txt");
    FileInputStream fis = null;
    try {
    fis = new FileInputStream(f);
    InputStreamReader isr = new InputStreamReader(fis,"utf-8");
    int temp = 0;
    while((temp=isr.read())!=-1){
    char c = (char) temp;

    System.out.print(c);
    }
    } catch (FileNotFoundException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    }finally{
    try {
    if (fis!=null) {
    fis.close();
    }
    } catch (IOException e) {
    e.printStackTrace();
    }
    }
    }
    }

  • 相关阅读:
    AT SELECTIONSCREEN的用法
    ADD的用法
    ~的用法
    DIV+CSS布局
    CSS 列表
    CSS 文本
    VC include 路径解析
    CRITICAL_SECTION临界区学习
    UI设计时要注意的几个方面
    使用和扩展marshal_as库
  • 原文地址:https://www.cnblogs.com/7758521gorden/p/8046460.html
Copyright © 2011-2022 走看看