我使用Java的1.8.0-的OpenJDK-AMD64過的Ubuntu 16.04的Java IO附加到文件實現
我試圖瞭解發生了什麼文件,而我追加
讓我們假設我m附加到一個非常大的文件,Java是否將整個文件加載到內存中?我怎樣才能看到本地電話?
從java.io.FileOutputStream.java
/**
* Opens a file, with the specified name, for overwriting or appending.
* @param name name of file to be opened
* @param append whether the file is to be opened in append mode
*/
private native void open0(String name, boolean append)
throws FileNotFoundException;
// wrap native call to allow instrumentation
/**
* Opens a file, with the specified name, for overwriting or appending.
* @param name name of file to be opened
* @param append whether the file is to be opened in append mode
*/
private void open(String name, boolean append)
throws FileNotFoundException {
open0(name, append);
}
更新:
看着jdk8源代碼
的src /的Solaris /本地/陽光/ NIO/CH/InheritedChannel。 c:Java_sun_nio_ch_InheritedChannel_open0(JNIEnv * env,jclass cla,jstring path,jint oflag)
JNIEXPORT jint JNICALL
Java_sun_nio_ch_InheritedChannel_open0(JNIEnv *env, jclass cla, jstring path, jint oflag)
{
const char* str;
int oflag_actual;
/* convert to OS specific value */
switch (oflag) {
case sun_nio_ch_InheritedChannel_O_RDWR :
oflag_actual = O_RDWR;
break;
case sun_nio_ch_InheritedChannel_O_RDONLY :
oflag_actual = O_RDONLY;
break;
case sun_nio_ch_InheritedChannel_O_WRONLY :
oflag_actual = O_WRONLY;
break;
default :
JNU_ThrowInternalError(env, "Unrecognized file mode");
return -1;
}
str = JNU_GetStringPlatformChars(env, path, NULL);
if (str == NULL) {
return (jint)-1;
} else {
int fd = open(str, oflag_actual);
if (fd < 0) {
JNU_ThrowIOExceptionWithLastError(env, str);
}
JNU_ReleaseStringPlatformChars(env, path, str);
return (jint)fd;
}
}
https://stackoverflow.com/questions/12594046/java-native-method-source-code – Tom