IO体系和源码

版权声明:本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在页面明显位置给出原文链接。 https://blog.csdn.net/mengxiangqihangz/article/details/85161640

FileInputStream:文件输入流

体系:首先是执行initIDs方法,设置属性在对象内存中的偏移量
使用时,先open,
可以获取文件可以读取多少个字节的 available方法
跳过多少个字节开始读取数据的skip方法
读取单个字节的read0方法
读取字节数组的readBytes方法
以及关闭输入流的close0方法(基础方法多用同名方法加0表示)

private native void open(String name) throws FileNotFoundException;//Opens the specified file for reading.
private native int read0() throws IOException;//读取单个字节
private native int readBytes(byte b[], int off, int len) throws IOException;//Reads a subarray as a sequence of bytes,读取一个子数组,作为bytes的结果
public native long skip(long n) throws IOException;//跳过多少个字节
public native int available() throws IOException;//Returns an estimate of the number of remaining bytes that can be read //返回还未读取的字节 数
private static native void initIDs();//它的作用是设置类中(也就是FileInputStream)的属性的内存地址偏移量,便于在必要时操作内存给它赋值
private native void close0() throws IOException;

FileOutputStream:文件输出流

体系:首先是执行initIDs方法,设置属性在对象内存中的偏移量
使用时,先open,
然后可以write int或者 字节数组。
然后是关闭 输出流

private native void open(String name, boolean append) throws FileNotFoundException;
private native void write(int b, boolean append) throws IOException;
private native void writeBytes(byte b[], int off, int len, boolean append) throws IOException;
private native void close0() throws IOException;
private static native void initIDs();

FileDescriptor(可以不用了解)

引:https://blog.csdn.net/Holmofy/article/details/75269866
引:https://blog.csdn.net/moakun/article/details/78638571
引:http://www.cnblogs.com/skywang12345/p/io_09.html
引:https://baike.baidu.com/item/文件描述符/9809582?fr=aladdin
文件描述符
在形式上是一个非负整数。实际上,它是一个索引值,指向内核为每一个进程所维护的该进程打开文件的记录表。当程序打开一个现有文件或者创建一个新文件时,内核向进程返回一个文件描述符。在程序设计中,一些涉及底层的程序编写往往会围绕着文件描述符展开。但是文件描述符这一概念往往只适用于UNIX、Linux这样的操作系统。
习惯上,标准输入(standard input)的文件描述符是 0,标准输出(standard output)是 1,标准错误(standard error)是 2

try {
    FileOutputStream out = new FileOutputStream(FileDescriptor.out);
    out.write('A');
    out.close();
} catch (IOException e) {
	
}

猜你喜欢

转载自blog.csdn.net/mengxiangqihangz/article/details/85161640