public class StreamChange {    public static void func(DataInputStream in, DataOutputStream out) {
private byte[] temp = new byte [48]; HXDRFCHD h = new HXDRFCHD();

h.setLHdSize(in.readLong());
    }

    public static void main(String[] args) {
        ............
func(in, out);
        ............
    }
}

解决方案 »

  1.   

    to:registered(已注册)
        按你的程序修改后,还是有错: Illegal modifier for parameter temp; only final is permitted
    in cannot be resolved
    out cannot be resolved请问是何原因?应该如何解决,谢谢
      

  2.   

    你这句话写错了
    private byte[] temp = new byte [48];
    应该是
    byte[] temp = new byte [48];
      

  3.   

    哦,加顺手了多加了。不过这两个错误in cannot be resolved ;out cannot be resolved什么意思,还请指点怎么解决
      

  4.   

    根据你这句话:
    "我这个in是要从别处调用来的,所以这里我不是很清楚。如果是要接收从外部来的流的话,程序应该怎么编才不出错??请指教"
    你应该有"外部获得"的 in 和 out
    获得以后将他们以参数形式传递给 func(in, out);
    我上面贴的代码只是示意一下, 并不保证编译通过...
    如果你在其他类调用这个函数, 那把 main 删掉就能编译通过了还有一个疑问: 你说的外部获得指的是什么?
      

  5.   

    哦,非常感谢,我已经懂了。我说的外部获得是指那个in是由其他程序传给我的。还有个问题,如果用DataInput接口来实现是否可行?
      

  6.   

    用什么 Stream 取决于"外部获得"的 Stream
    例如如果从标准输出(System.out)获得的 OutputStream 应该是 PrintStream
    当然你也可以用多态的性质, 使用输入输出"鼻祖"类(所有io类均继承于此等类) InputStream 和 OutputStream 或 Reader 和 Writer
    不过使用"某类独有"(Class Specific)的方法的时候, 需要将其转型(Cast)
    如:
    InputStream in;
    ((ObjectInputStream) in).readObject();因为 readObject() 为 ObjectInputStream 特有, 所以需要转型后方可使用