Io Java虚拟机如何处理I/O操作?

Io Java虚拟机如何处理I/O操作?,io,jvm,java,Io,Jvm,Java,我正在查看的列表中,我注意到没有任何I/O指令。这引起了我的兴趣。当JVM不支持I/O指令时,它如何执行诸如System.out.println之类的方法 如果它使用某种形式的内存映射I/O,那么它如何与操作系统通信以读取文件描述符等?JVM是否实现了自己的抽象层来处理I/O操作?Java I/O包(Java.io和Java.nio)是用C/C++实现的吗?如果您查看库源代码,您会发现所有与低级API(OS等)的接口都是使用本机代码完成的 例如,以FileOutputStream为例: /**

我正在查看的列表中,我注意到没有任何I/O指令。这引起了我的兴趣。当JVM不支持I/O指令时,它如何执行诸如
System.out.println
之类的方法


如果它使用某种形式的内存映射I/O,那么它如何与操作系统通信以读取文件描述符等?JVM是否实现了自己的抽象层来处理I/O操作?Java I/O包(Java.io和Java.nio)是用C/C++实现的吗?

如果您查看库源代码,您会发现所有与低级API(OS等)的接口都是使用本机代码完成的

例如,以
FileOutputStream
为例:

/**
 * Opens a file, with the specified name, for writing.
 * @param name name of file to be opened
 */
private native void open(String name) throws FileNotFoundException;

/**
 * Writes the specified byte to this file output stream. Implements
 * the <code>write</code> method of <code>OutputStream</code>.
 *
 * @param      b   the byte to be written.
 * @exception  IOException  if an I/O error occurs.
 */
public native void write(int b) throws IOException;

/**
 * Writes a sub array as a sequence of bytes.
 * @param b the data to be written
 * @param off the start offset in the data
 * @param len the number of bytes that are written
 * @exception IOException If an I/O error has occurred.
 */
private native void writeBytes(byte b[], int off, int len) throws IOException;

然后是相应的C文件(通常是特定于操作系统的)。

接口是内存映射、I/O(隔离)映射还是转移到IOP在这一级别上并不重要。对于那些不懂术语的人来说,“本机代码”指的是用Java以外的语言实现的代码。