
下面的java文件编译的时候不能通过
importjava.io.*;classFileStream{publicstaticvoidmain(String[]agrs)throwsIOException{F...
import java.io.*;
class FileStream
{
public static void main(String[] agrs)throws IOException
{
FileOutputStream fos = new FileOutputStream("fos.txt");
fos.write("adsfaf".getBytes());
fos.close();
FileInputStream fis = new FileInputStream("fos.txt");
Byte[] buf = new Byte[1024];
int len = 0;
while((len=fis.read(buf))!=-1);
{
System.out.println(new String(buf,0,len));
}
fis.close();
}
} 展开
class FileStream
{
public static void main(String[] agrs)throws IOException
{
FileOutputStream fos = new FileOutputStream("fos.txt");
fos.write("adsfaf".getBytes());
fos.close();
FileInputStream fis = new FileInputStream("fos.txt");
Byte[] buf = new Byte[1024];
int len = 0;
while((len=fis.read(buf))!=-1);
{
System.out.println(new String(buf,0,len));
}
fis.close();
}
} 展开
1个回答
展开全部
哥们,我不知道你是不是故意的,呵呵! 不过,我还是回答一下你:
你这个代码:
Byte[] buf = new Byte[1024];
定义的是一个对象类型Byte的数组, 而不是基本类型 byte 数组.
但是,字节输入流的 read 方法的参数需要的是一个 byte[], 而不是 Byte[]
这就是编译通不过的原因.
虽然, Byte和 byte 之间有自动解封箱功能,但是, Byte[] 和 byte[] 之间没有.
因为数组本身就是对象类型, 不管你是对象类型数组或是基本类型数组.
不知道这样回答,你是否满意呢?
你这个代码:
Byte[] buf = new Byte[1024];
定义的是一个对象类型Byte的数组, 而不是基本类型 byte 数组.
但是,字节输入流的 read 方法的参数需要的是一个 byte[], 而不是 Byte[]
这就是编译通不过的原因.
虽然, Byte和 byte 之间有自动解封箱功能,但是, Byte[] 和 byte[] 之间没有.
因为数组本身就是对象类型, 不管你是对象类型数组或是基本类型数组.
不知道这样回答,你是否满意呢?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询