zoukankan      html  css  js  c++  java
  • java 多种方式文件读取

     1 import java.io.File;
    2 import java.io.InputStream;
    3 import java.io.FileInputStream;
    4 //import org.omg.CORBA_2_3.portable.OutputStream;
    5 public class dm {
    6 public static void main(String[] args) throws Exception {
    7 File f=new File("d:"+File.separator+"te.txt");
    8 InputStream out=new FileInputStream(f);
    9 byte b[]=new byte[(int)f.length()];
    10 out.read(b);
    11 out.close();
    12 System.out.println("内容为:"+new String(b));
    13 }
    14 }

    关键是第九行:

      1.for(int i=0;i<b.length;i++){
          b[i]=(byte)out.read();

        }

            已经知道数组大小,开展输出。

      2.while(temp=out.read())!=-1){

          b[len]=(byte)temp;

          len++;

        }

       文件读到末尾了,返回值为-1。

  • 相关阅读:
    第二阶段冲刺—第三天
    团队测试计划
    第二阶段冲刺—第二天
    第二阶段冲刺—第一天
    评分表
    针对每个组建议的改进
    第二阶段团队绩效评分
    项目总结
    会议2.10
    会议2.9
  • 原文地址:https://www.cnblogs.com/dennisac/p/2408523.html
Copyright © 2011-2022 走看看