欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Java IO 流(1)IO流介绍

程序员文章站 2022-04-03 08:15:13
...

Java IO 流(1)IO流介绍

IO流定义:

流的本质是一组单向有序,分起始和终止的数据传输过程。需要导入import java.io.\*

IO流分类:

按数据类型分为:字节流和字符流

字节流:
按字节进行读取(可以处理任意类型数据)
字符流
字节流 \+ 编码表(处理纯文本数据优先考虑)

Java IO 流(1)IO流介绍

按数据流向分为:输入流和输出流

输入流
有Reader(字符输入流)、InputStream(字节输入流)
输出流
 有Writer(字符输出流)、OutputStream(字节输出流)

按复杂程度分为:基本流和包装流

基本流
包装流

IO 流四大基类

InputStream (字节输入流)

Java IO 流(1)IO流介绍

public abstract class InputStream
extends Object
implements Closeable

构造方法及成员方法

​InputStream() //是所有数据输入字节流的基类

int         	available()
void	    	close()
void	    	mark(int readlimit)
boolean	    	markSupported()
abstract   int  read()
int	    		read(byte[] b)
int	    		read(byte[] b, int off, int len)
void	    	reset()
long	    	skip(long n)

OutputStream (字节输出流)

Java IO 流(1)IO流介绍

public abstract class OutputStream
extends OutputStream
//字节流可以处理以字节为单位的任何数据类型

构造方法及成员方法

​OutputStream() //是所有数据输出字节流的基类

abstract void	write_any(Any value)
abstract void	write_boolean_array(boolean[] value, int offset, int length)

abstract void	write_boolean(boolean value)

abstract void	write_char_array(char[] value, int offset, int length)

abstract void	write_char(char value)

void			write_Context(Context ctx, ContextList contexts)

abstract void	write_double_array(double[] value, int offset, int length)

abstract void	write_double(double value)

void			write_fixed(BigDecimal value)

abstract void	write_float_array(float[] value, int offset, int length)

abstract void	write_float(float value)

abstract void	write_long_array(int[] value, int offset, int length)

abstract void	write_long(int value)

abstract void	write_longlong_array(long[] value, int offset, int length)

abstract void	write_longlong(long value)
W
abstract void	write_Object(Object value)

abstract void	write_octet_array(byte[] value, int offset, int length)

abstract void	write_octet(byte value)

void			write_Principal(Principal value)

abstract void	write_short_array(short[] value, int offset, int length)

abstract void	write_short(short value)

abstract void	write_string(String value)

abstract void	write_TypeCode(TypeCode value)

abstract void	write_ulong_array(int[] value, int offset, int length)

abstract void	write_ulong(int value)

abstract void	write_ulonglong_array(long[] value, int offset, int length)

abstract void	write_ulonglong(long value)

void			write(int b)

Reader (字符输入流)

Java IO 流(1)IO流介绍

public abstract class Reader
extends Object
implements Readable, Closeable

构造方法及成员方法

​Protected Reader()

Protected Reader(Object lock)

abstract void   close()
void	        mark(int readAheadLimit)
boolean	        markSupported()
int	        	read()
int	        	read(char[] cbuf)
abstract int	read(char[] cbuf, int off, int len)
int	        	read(CharBuffer target)
boolean	        ready()
void	        reset()
long	        skip(long n)

Writer (字符输出流)

Java IO 流(1)IO流介绍

public abstract class Writer
extends Object
implements Appendable, Closeable, Flushable

构造方法及成员函数

​protected Writer()

protected Writer(Object lock)

Writer	        append(char c)
Writer	        append(CharSequence csq)
Writer	        append(CharSequence csq, int start, int end)
abstract void	close()
abstract void	flush()
void	        write(char[] cbuf)
abstract void	write(char[] cbuf, int off, int len)
void	        write(int c)
void	        write(String str)
void	        write(String str, int off, int len)