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

  • 相关阅读:
    MSBuild、条件编译、预处理命令
    批量数据插入SqlBulkCopy
    WPF 双向绑定
    编程思想之一
    python 提交表单
    python 添加用户
    python 分页
    day9 IO多路复用
    day9 线程、进程和协程深入版
    day8 进程、线程 简介版
  • 原文地址:https://www.cnblogs.com/7758521gorden/p/8046460.html
Copyright © 2011-2022 走看看