Java 关于流的一道问题

来源:百度知道 编辑:UC知道 时间:2024/06/06 11:19:55
class ImpleMyIO implements MyIO
{
//读取f中的内容,放入byte[]中并返回
public byte[] getInput(File f){

}
//将b中的内容写入到f中
public boolean output(File f,byte[] b){

}
}
class Example4
{
public static void main(String[] args)
{
MyIO io = new ImpleMyIO();
File f = new File("a.txt");
byte[] b = io.getInput(f);
File f1 = new File("b.txt");
io.output(f1,b);
}
}
里面的内容怎么写 我今天刚刚学的流 我的答案是
import java.io.*;
interface MyIO
{
public byte[] getInput(File f);
public boolean output(File f, byte[] b);
}
class ImpleMyIO implements MyIO
{
public byte[] getInput(File f){
InputStream in = null;
try
{
in = new FileInputStream(f);
int i = in.available();
byte[] b = new byte[i];
in.read(b);
for(int j= 0;j<b.length;j++){
System.out.print((char)b[j]);

public boolean output(File f, byte[] b){
OutputStream out = null;
try{
out = new FileOutputStream(f,true);
out.write(b);

}catch(Exception e){

}
改成
public boolean output(File f, byte[] b){
private boolean flag = false;
OutputStream out = null;
try{
out = new FileOutputStream(f,true);
out.write(b);
return flag = true;
}catch(Exception e){
return flag = false;
}
试一下 我也不知道对不对 呵呵 大家一起学哈

我没看你写的内容,我就知道你这个函数没有return个Boolean值。
public boolean output(File f, byte[] b){
OutputStream out = null;
try{
out = new FileOutputStream(f,true);
out.write(b);

}catch(Exception e){

}

的确 上面返回值类型 是 boolean
而下面 却没有return