gpt4 book ai didi

java - 为什么Java的FileInputStream read()带参数,而Oracle的文档却说不带参数?

转载 作者:行者123 更新时间:2023-12-02 05:33:06 28 4
gpt4 key购买 nike

我正在阅读一本 Java 考试准备书。当我读到下面的例子时,我很困惑:

byte [] magicNumber = {( byte) 0xCA, (byte) 0xFE, (byte) 0xBA, (byte) 0xBE}; 
try (FileInputStream fis = new FileInputStream( fileName)) {
byte[] u4buffer = new byte[ 4];
if( fis.read( u4buffer) != − 1) {
if( Arrays.equals( magicNumber, u4buffer)) {
System.out.printf(" The magic number for passed file %s matches that of a .class file", fileName);
} else {
System.out.printf(" The magic number for passed file %s does not match that of a .class file", fileName);
}
}
} catch( FileNotFoundException fnfe) {
System.err.println(" file does not exist with the given file name ");
} catch( IOException ioe) {
System.err.println(" an I/ O error occurred while processing the file");
}

这是什么意思:read(u4buffer)

最佳答案

查看 FileInputStream 的文档

read 方法使用不同的参数集重载两次。

您可能想阅读有关 method overloading 的更多信息.

关于java - 为什么Java的FileInputStream read()带参数,而Oracle的文档却说不带参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25329312/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com