zoukankan      html  css  js  c++  java
  • java读取文件内容并输出到控制台,java中实现文件复制

    public class TestFileInputStream {
      public static void main(String [] args) {
        //读取指定文件中内容,并在控制台输出
        FileInputStream fis = null;
        byte[] b = new byte[1024];
        int len = 0;

        try {
          fis = new FileInputStream("E:\\javafile\\ja.txt");
          while((len = fis.read(b)) != -1) {
            System.out.write(b, 0, len);
          }
        } catch (IOException e) {
          e.printStackTrace();
        }finally {
          try {
            fis.close();
          } catch (IOException e) {
            e.printStackTrace();
          }
        }
      }
    }

    public class TestFileInputStream{
      public static void main(String [] args) {
        //实现文件复制
        FileInputStream fis = null;
        FileOutputStream fos = null;

        byte[] b = new byte[1024];
        int len = 0;

        try {
          fis = new FileInputStream("E:\\javafile\\ja.txt");
          fos = new FileOutputStream("E:\\javafile\\jc.txt");

          while((len = fis.read(b)) != -1) {
            fos.write(b, 0, len);
          }

        } catch (FileNotFoundException e) {
          e.printStackTrace();
        }catch(IOException io) {
          io.printStackTrace();
        }finally {
          try {
            fis.close();
            fos.close();
          } catch (IOException e) {
            e.printStackTrace();
          }
        }
      }
    }

  • 相关阅读:
    【BZOJ】4011: [HNOI2015]落忆枫音
    【BZOJ】1187: [HNOI2007]神奇游乐园
    【CERC2007】机器排序
    【NOI2004】郁闷的出纳员
    【USACO】奶牛跑步2
    【HNOI2004】宠物收养所
    【NOI2009】植物大战僵尸
    Xn数列
    骨牌覆盖
    【JSOI2008】球形空间产生器
  • 原文地址:https://www.cnblogs.com/helloworldlx/p/8507975.html
Copyright © 2011-2022 走看看