黑马程序员技术交流社区
标题: 关于DataInputStream的简单问题 [打印本页]
作者: 小杨 时间: 2012-6-6 17:27
标题: 关于DataInputStream的简单问题
- DataInputStream in5 = new DataInputStream(new BufferedInputStream(new FileInputStream("Data.txt")));
- System.out.println(in5.readLine());
- System.out.println(in5.readDouble());
复制代码这段代码里DataInputStream.readLine过时,在功能不变的情况下怎么改?
如果用BufferedReader,它没有readDouble类似的方法呀?
作者: 张少威 时间: 2012-6-6 17:29
自己写个DataInputStream的代理类呗- class DataInputStreamProxy implements DataInput {
- private DataInputStream dis;
- private BufferedReader br;
- public DataInputStreamProxy(DataInputStream dis) {
- this.dis = dis;
- br = new BufferedReader(new InputStreamReader(new BufferedInputStream(dis)));
- }
- @Override
- public void readFully(byte[] b) throws IOException {
- dis.readFully(b);
- }
- @Override
- public void readFully(byte[] b, int off, int len) throws IOException {
- dis.readFully(b, off, len);
- }
- @Override
- public int skipBytes(int n) throws IOException {
- return dis.skipBytes(n);
- }
- @Override
- public boolean readBoolean() throws IOException {
- return dis.readBoolean();
- }
- @Override
- public byte readByte() throws IOException {
- return dis.readByte();
- }
- @Override
- public int readUnsignedByte() throws IOException {
- return dis.readUnsignedByte();
- }
- @Override
- public short readShort() throws IOException {
- return dis.readShort();
- }
- @Override
- public int readUnsignedShort() throws IOException {
- return dis.readUnsignedShort();
- }
- @Override
- public char readChar() throws IOException {
- return dis.readChar();
- }
- @Override
- public int readInt() throws IOException {
- return dis.readInt();
- }
- @Override
- public long readLong() throws IOException {
- return dis.readLong();
- }
- @Override
- public float readFloat() throws IOException {
- return dis.readFloat();
- }
- @Override
- public double readDouble() throws IOException {
- return dis.readDouble();
- }
- @Override
- public String readLine() throws IOException {
- return br.readLine();
- }
- @Override
- public String readUTF() throws IOException {
- return null;
- }
- }
复制代码
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) |
黑马程序员IT技术论坛 X3.2 |