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

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-13
  • 2021-11-02
  • 2021-11-19
  • 2021-07-21
  • 2022-02-15
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-30
  • 2021-06-05
  • 2022-12-23
  • 2021-05-25
  • 2022-12-23
相关资源
相似解决方案