zoukankan      html  css  js  c++  java
  • 字节输入流-InputStream demo4

    package inputstream.cn;
    
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.InputStream;
    
    /*
     * 改进版 4
     * 使用read()通过循环读取
     * byte[] b = new byte[(int)f.length()];
                for (int i = 0; i < b.length; i++) {
                        b[i] = (byte)is.read();
                }
     */
    public class InputStreamDemo4 {
            public static void main(String[] args) throws Exception {
                //使用file 找到一个文件
                File f = new File("d:"+File.separator+"test.txt");
                //通过子类实例化父类
                InputStream is =new FileInputStream(f);
                //开辟一个1024的字节数组,把所有的类容读到此数组中
                byte[] b = new byte[(int)f.length()];
                for (int i = 0; i < b.length; i++) {
                        b[i] = (byte)is.read();
                }
                //关闭输入流
                is.close();
                //打印读的数据,将byte类型转换为string类型输出
                System.out.println(new String(b));
                
            }
        }
  • 相关阅读:
    分布式和集群
    c++ >>
    c++ ip地址相关
    c++ ip地址的操作 c版
    c++ 缺少动态库
    c++ dirname() basename()
    shell ulimit -n
    shell 进程查询相关的命令
    shell grep 高亮
    c++ swap 函数
  • 原文地址:https://www.cnblogs.com/yuanyuan2017/p/6946373.html
Copyright © 2011-2022 走看看