import java.io.*;
public class io{ public static void main(String a[]){
byte []b;b=new byte[6];
int t=0;
try{ DataInputStream i=new DataInputStream( ByteArrayInputStream.in); int str=i.read(b);
System.out.println(str);
for (int k=0;k<6;k++)
System.out.println("b["+k+"]="+b[k]);
}catch(Exception e){System.out.println(e.toString());
}
}}
public class io{ public static void main(String a[]){
byte []b;b=new byte[6];
int t=0;
try{ DataInputStream i=new DataInputStream( ByteArrayInputStream.in); int str=i.read(b);
System.out.println(str);
for (int k=0;k<6;k++)
System.out.println("b["+k+"]="+b[k]);
}catch(Exception e){System.out.println(e.toString());
}
}}
是从键盘输入吗?
还是要从文件里读?
还是别的什么功能?
如果是想从键盘输入的话:
/*
import java.io.*;
public class io{ public static void main(String a[]){
byte []b;b=new byte[6];
int t=0;
try{ DataInputStream i=new DataInputStream(System.in); int str=i.read(b);
System.out.println(str);
for (int k=0;k<6;k++)
System.out.println("b["+k+"]="+b[k]);
}catch(Exception e){System.out.println(e.toString());
}
}}
先看看JAVA帮助文档 用System.in作为参数放进去DateInputStream构造函数中就行了
DataInputStream i=new DataInputStream( System.in );
public class io{public static void main(String a[]){
byte []b;b=new byte[6];
int t=0;try{ DataInputStream i=new DataInputStream(System.in); int str=i.read(b);
System.out.println(str);
for (int k=0;k<6;k++)
System.out.println("b["+k+"]="+(char)b[k]);
}catch(Exception e){System.out.println(e.toString());
}
}}
加一个强制转换就可以了