Java DataInputStream Read Line readLine(DataInputStream ds)

Here you can find the source of readLine(DataInputStream ds)

Description

read a line from InputStreamReader, it will block until a '\n' is read.

License

Open Source License

Parameter

Parameter Description
ds the DataInputStream.

Return

the String contains the last line read from the DataInputStream.

Declaration

public static String readLine(DataInputStream ds) throws IOException 

Method Source Code


//package com.java2s;
/* Util.java/*ww  w  .j  av a  2 s  .  co m*/
    
   Copyright (C) 2001  Yu Zhang
    
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
    
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
    
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the 
   Free Software Foundation, Inc., 
   59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

import java.io.*;

public class Main {
    /**
     * read a line from InputStreamReader, it will block until a '\n' is read.
     *
     * @param ds the DataInputStream.
     * @return the String contains the last line read from the DataInputStream.
     * @exception IOException If any IO problems occured.
     */
    public static String readLine(DataInputStream ds) throws IOException {
        StringBuffer sb = new StringBuffer();
        int c = ds.readByte();
        while (c != '\n' && c != -1) {
            sb.append((char) c);
            c = ds.readByte();
        }

        return sb.toString();
    }
}

Related

  1. readLine(DataInputStream dis)
  2. readLine(DataInputStream in)