zl程序教程

您现在的位置是:首页 >  后端

当前栏目

fileinputstream java_Java FileInputStream close()方法

JAVA方法 CLOSE FileInputStream
2023-06-13 09:11:33 时间

大家好,又见面了,我是你们的朋友全栈君。

Java FileInputStream close()方法

java.io.FilterInputStream.close() 用于关闭流。

1 语法

public void close()

2 参数

3 返回值

4 示例

package com.yiidian;

/**

* 一点教程网: http://www.yiidian.com

*/

/**

* java.io.FilterInputStream.close()方法的例子

*/

import java.io.BufferedInputStream;

import java.io.FileInputStream;

import java.io.FilterInputStream;

import java.io.IOException;

import java.io.InputStream;

public class Demo {

public static void main(String[] args) throws Exception {

InputStream is = null;

FilterInputStream fis = null;

try {

// create input streams

is = new FileInputStream(“d://test.txt”);

fis = new BufferedInputStream(is);

// closes and releases the associated system resources

fis.close();

// read is called after close() invocation

fis.read();

} catch(IOException e) {

System.out.print(“stream is closed prior ot this call”);

} finally {

// releases any system resources associated with the stream

if(is!=null)

is.close();

if(fis!=null)

fis.close();

}

}

}

假设test.txt的内容如下:

ABCDE

输出结果为:

stream is closed prior ot this call

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/145904.html原文链接:https://javaforall.cn