• Java里的IO流里的FileInputStream 的读取并在前打印行数!


    大家好!!新人求罩!

     1 import java.io.File;
     2 import java.io.FileInputStream;
     3 import java.io.FileNotFoundException;
     4 import java.io.IOException;
     5 
     6 
     7 public class work6 {
     8 
     9     /**
    10      * @param args
    11      * @throws IOException 
    12      */
    13     public static void main(String[] args) throws IOException {
    14         // TODO Auto-generated method stub
    15         File file = new File("C:\Users\wang\Desktop\io作业.txt");//文件的地址!!!
    16         //System.out.println(file.exists());
    17         FileInputStream in = new FileInputStream(file);
    18         
    19         byte[] b = new byte[1024];
    20         
    21         int c = 0;
    22         
    23         String str = "";
    24         
    25         while((c = in.read(b)) != -1){
    26              str += new String(b,0,c);//在此拼接
    27         }
    28         String[] s = str.split("
    ");//以
    来截取!转化为数组!
    29         for(int i = 0; i < s.length; i++){//遍历当前数组!
    30             System.out.print((i+1)+"	"+s[i]);
    31         }
    32     }
    33 
    34 }

    一个简单的读取就完成了!!就是这么简单!

  • 相关阅读:
    Log4j2 打印日志实践
    解决docker容器启动不了,处于Exited问题
    dockerfile如何编写
    mysql(查询从句)
    线性表代码实现
    mysql(子查询)
    mysql(连表查询)
    mysql(基础命令)
    mysql安装
    mysql建表
  • 原文地址:https://www.cnblogs.com/a710445786/p/6136326.html
Copyright © 2020-2023  润新知