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();
    }
    }
    }
    }

  • 相关阅读:
    OCP-1Z0-053-V13.02-702题
    OCP-1Z0-053-V13.02-688题
    OCP-1Z0-053-V13.02-691题
    OCP-1Z0-053-V13.02-698题
    OCP-1Z0-053-V13.02-703题
    OCP-1Z0-053-V13.02-701题
    OCP-1Z0-053-V13.02-685题
    memcached 按键查找和批量查找
    catch(CException *e)捕获异常
    char数组最大长度
  • 原文地址:https://www.cnblogs.com/7758521gorden/p/8046460.html
Copyright © 2011-2022 走看看