📜  Java I/O-FilterInputStream

📅  最后修改于: 2020-09-27 03:19:14             🧑  作者: Mango

Java FilterInputStream类

Java FilterInputStream类实现InputStream。它包含不同的子类,例如BufferedInputStream,DataInputStream,以提供附加功能。因此,它很少单独使用。

Java FilterInputStream类声明

我们来看一下java.io.FilterInputStream类的声明

public class FilterInputStream extends InputStream

Java FilterInputStream类方法

Method Description
int available() It is used to return an estimate number of bytes that can be read from the input stream.
int read() It is used to read the next byte of data from the input stream.
int read(byte[] b) It is used to read up to byte.length bytes of data from the input stream.
long skip(long n) It is used to skip over and discards n bytes of data from the input stream.
boolean markSupported() It is used to test if the input stream support mark and reset method.
void mark(int readlimit) It is used to mark the current position in the input stream.
void reset() It is used to reset the input stream.
void close() It is used to close the input stream.

FilterInputStream类的示例

import java.io.*;
public class FilterExample {
public static void main(String[] args) throws IOException {
File data = new File("D:\\testout.txt");
FileInputStream  file = new FileInputStream(data);
FilterInputStream filter = new BufferedInputStream(file);
int k =0;
while((k=filter.read())!=-1){
System.out.print((char)k);
}
file.close();
filter.close();
}
}

在这里,我们假设您在“ testout.txt”文件中包含以下数据:

Welcome to javatpoint

输出:

Welcome to javatpoint