Java 为什么FileInputStream这么慢?
我正在使用Java 为什么FileInputStream这么慢?,java,linux,inputstream,Java,Linux,Inputstream,我正在使用RHEL7 我正在开发一个应用程序,它应该从外部加载大量数据。我有ramdisk,它存储在RAM中,应该读得很快。我通过两种方式访问它: FileInputStream public static void main(String [] args){ try(InputStream fis = new FileInputStream(new File("/mnt/ramdisk/file")) BufferedReader r = new BufferedRe
RHEL7
我正在开发一个应用程序,它应该从外部加载大量数据。我有ramdisk
,它存储在RAM
中,应该读得很快。我通过两种方式访问它:
FileInputStream
public static void main(String [] args){
try(InputStream fis = new FileInputStream(new File("/mnt/ramdisk/file"))
BufferedReader r = new BufferedReader(new InputStreamReader(fis))){
while(//till the end of stream
){
byte[] buffer = new byte[_some_size_];
r.read(buffer);
//Do something useful
}
}
系统中的cat ramdisk/file | java-cp my.jar com.test.Main
The same as 1, but the stream is System.in.
有人能解释一下性能差异吗?我想了解它 请分享你的代码。如果不查看您如何读取流(使用
FileInputStream
或System.in
),我们无法告诉您出了什么问题。另外,如何使用FileInputStream
读取内存中的内容?@反斜杠非常简单。只需要创建RAM磁盘。好的,第一点呢?你能分享你的代码吗?@BackSlash DoneSystem.in是抽象的。实际的实例是什么?请分享你的代码。如果不查看您如何读取流(使用FileInputStream
或System.in
),我们无法告诉您出了什么问题。另外,如何使用FileInputStream
读取内存中的内容?@反斜杠非常简单。只需要创建RAM磁盘。好的,第一点呢?你能分享你的代码吗?@BackSlash DoneSystem.in是抽象的。实际情况如何?