FileInputStream类close()方法 (FileInputStream Class close() method)

  • close() method is available in java.io package.

    close()方法在java.io包中可用。

  • close() method is used to close this FileInputStream and free all system resources linked with this stream.

    close()方法用于关闭此FileInputStream并释放与此流链接的所有系统资源。

  • close() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.

    close()方法是一个非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。

  • close() method may throw an exception at the time of closing the stream.

    close()方法在关闭流时可能会引发异常。

    IOException: This exception may throw while getting any input/output error or when this stream is closed by close() method.

    IOException :在获取任何输入/输出错误时或通过close()方法关闭此流时,可能引发此异常。

Syntax:

句法:

    public void close();

Parameter(s):

参数:

  • It does not accept any parameter.

    它不接受任何参数。

Return value:

返回值:

The return type of the method is void, it returns nothing.

该方法的返回类型为void ,不返回任何内容。

Example:

例:

// Java program to demonstrate the example
// of void close() method of FileInputStream
import java.io.*;
public class CloseOfFIS {public static void main(String[] args) throws Exception {FileInputStream fis_stm = null;
int count = 0;
try {// Instantiates FileInputStream
fis_stm = new FileInputStream("D:\\includehelp.txt");
// By using read() method is to read
// a byte from fis_stm
count = fis_stm.read();
// Display corresponding bytes value
byte b = (byte) count;
// Display value of b
System.out.println("fis_stm.read(): " + b);
// By using close() method is to close
// close the stream
fis_stm.close();
// when we call read() method after
// closing the stream will result an exception
count = fis_stm.read();
} catch (Exception ex) {System.out.println(ex.toString());
} finally {// with the help of this block is to
// free all necessary resources linked
// with the stream
if (fis_stm != null) {fis_stm.close();
}
}
}
}

Output

输出量

fis_stm.read(): 0
java.io.IOException: Stream Closed

翻译自: https://www.includehelp.com/java/fileinputstream-close-method-with-example.aspx

Java FileInputStream close()方法与示例相关推荐

  1. Java IOUtils.copy方法代码示例(亲测)

    本文整理汇总了Java中org.apache.commons.io.IOUtils.copy方法的典型用法代码示例.如果您正苦于以下问题:Java IOUtils.copy方法的具体用法?Java I ...

  2. java中文件流close_Java FileInputStream close()方法与示例

    FileInputStream类close()方法close()方法在java.io包中可用. close()方法用于关闭此FileInputStream并释放与此流链接的所有系统资源. close( ...

  3. Java序列化魔术方法及其示例使用

    在上一篇文章中, 您需要了解有关Java序列化的所有知识 ,我们讨论了如何通过实现Java序列化来启用类的可序列化性. Serializable接口. 如果我们的类未实现Serializable接口, ...

  4. inputstream 关闭 java,Java ObjectInputStream close()方法与示例

    ObjectInputStream类close()方法close()方法在java.io包中可用. close()方法用于关闭此ObjectInputStream并释放与此流链接的所有系统资源. cl ...

  5. java user directory,Java ProcessBuilder directory()方法与示例

    语法:public File directory (); public ProcessBuilder directory (File dir); ProcessBuilder类directory()方 ...

  6. catalog java,Java Connection getCatalog()方法与示例

    通常,目录是一个目录,其中包含有关数据集,文件或数据库的信息.而数据库目录中包含所有数据库,基本表,视图(虚拟表),同义词,值范围,索引,用户和用户组的列表. Connection接口的getCata ...

  7. filepermission java,Java FilePermission getActions()方法与示例

    FilePermission类getActions()方法getActions()方法在java.io包中可用. getActions()方法用于检查此FilePermission和给定对象在路径名和 ...

  8. java方法参数Bundle,Java ResourceBundle keySet()方法及示例

    ResourceBundle类keySet()方法keySet()方法在java.util包中可用. keySet()方法用于从此ResourceBundle及其超级捆绑包中获取所有现有键,以在Set ...

  9. java exec waitfor,Java Process waitFor()方法与示例

    流程类waitFor()方法在java.lang包中提供了waitFor()方法. waitFor()方法用于使当前正在运行的线程在需要时等待,直到由该Process对象表示的进程完成其终止为止. 当 ...

  10. java arraylist.add(),Java ArrayList add()方法与示例

    ArrayList类add()方法 语法:public boolean add(T ele); public void add(int indices, T ele);add()方法在java.uti ...

最新文章

  1. 机械工业出版社之道格·赫尔曼《Python 3标准库》目录
  2. 第一章:OpenCV入门
  3. MySQL 排名函数.md
  4. Java中junit单元测试
  5. java recoed replay_easymock教程-record-replay-verify模型
  6. eclipse没有Web分支Dynamic Web Project
  7. linux的poll_wait函数,select() 与 poll()两个函数接口的作用
  8. 【二 HTTP编程】2. HTTP路由
  9. node mysql 事件循环_nodejs事件和事件循环详解
  10. java的类加载器体系结构和双亲委派机制
  11. [强化学习实战]深度Q学习-DQN算法原理
  12. quartus频率计 时钟设置_基于QuartusII的两种数字频率计的设计与比较
  13. ViewPager报UnsupportedOperationException: Required method instantiateItem was not overridden错误
  14. Android 隐藏APP图标
  15. VUCA时代下,如何有效提高项目成功率?
  16. Java语言基础Day07(API概述、Scanner、匿名对象、Random、对象数组、ArrayList)
  17. GIF动态图制作工具(免费),附教程
  18. 字节飞书前端三轮技术面+HR面
  19. 贝多芬第九交响第五乐章合唱歌词
  20. 看完全都会了!源码解读及如何保证线程安全?BAT大厂面试总结

热门文章

  1. crio电压采集 labview_NI cDAQ917采集温度方法
  2. H5 input输入限制最大位数,和调用小键盘需求发生冲突的解决办法
  3. jq实现前端文件上传
  4. 浅谈一下我了解的PWA
  5. 注意安全!XSS 和 XSRF
  6. 自适应宽度元素单行文本省略用法探究
  7. Python 离线 安装requests第三方库
  8. c语言else匹配问题
  9. autoLayout自动布局
  10. [Algorithm] 字符串匹配算法——KMP算法