Example usage for java.io DataInputStream readLine

List of usage examples for java.io DataInputStream readLine

Introduction

In this page you can find the example usage for java.io DataInputStream readLine.

Prototype

@Deprecated
public final String readLine() throws IOException 

Source Link

Document

See the general contract of the readLine method of DataInput.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {

    String thisLine;//from w  w w.j a  va 2  s.c  o  m
    URL u = new URL("http://www.google.com");
    DataInputStream theHTML = new DataInputStream(u.openStream());
    while ((thisLine = theHTML.readLine()) != null) {
        System.out.println(thisLine);
    }

}

From source file:lycos.java

public static void main(String[] args) {

    try {/*w w  w.  j  a va  2 s.c o m*/
        String thisLine;
        URL u = new URL("http://www.google.com");
        DataInputStream theHTML = new DataInputStream(u.openStream());
        while ((thisLine = theHTML.readLine()) != null) {
            System.out.println(thisLine);
        } // while loop ends here
    } catch (MalformedURLException e) {
        System.err.println(e);
    } catch (IOException e) {
        System.err.println(e);
    }

}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    String query = "name=yourname&email=youremail@yourserver.com";

    URLConnection uc = new URL("http:// your form ").openConnection();
    uc.setDoOutput(true);/* w ww.  j a  v a  2  s  . co  m*/
    uc.setDoInput(true);
    uc.setAllowUserInteraction(false);
    DataOutputStream dos = new DataOutputStream(uc.getOutputStream());

    // The POST line, the Accept line, and
    // the content-type headers are sent by the URLConnection.
    // We just need to send the data
    dos.writeBytes(query);
    dos.close();

    // Read the response
    DataInputStream dis = new DataInputStream(uc.getInputStream());
    String nextline;
    while ((nextline = dis.readLine()) != null) {
        System.out.println(nextline);
    }
    dis.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {

    URL google = new URL("http://www.google.com/");
    URLConnection googleConnection = google.openConnection();
    DataInputStream dis = new DataInputStream(googleConnection.getInputStream());
    StringBuffer inputLine = new StringBuffer();
    String tmp;/*from w ww  . j av a  2s  .  c o  m*/
    while ((tmp = dis.readLine()) != null) {
        inputLine.append(tmp);
        System.out.println(tmp);
    }
    // use inputLine.toString(); here it would have whole source
    dis.close();
}

From source file:SecurityManagerTest.java

public static void main(String[] args) throws Exception {
    try {//from   ww w  .  ja  v a  2  s  . c om
        System.setSecurityManager(new PasswordSecurityManager("Booga Booga"));
    } catch (SecurityException se) {
        System.err.println("SecurityManager already set!");
    }

    DataInputStream in = new DataInputStream(new FileInputStream("inputtext.txt"));
    DataOutputStream out = new DataOutputStream(new FileOutputStream("outputtext.txt"));
    String inputString;
    while ((inputString = in.readLine()) != null) {
        out.writeBytes(inputString);
        out.writeByte('\n');
    }
    in.close();
    out.close();
}

From source file:whois.java

public static void main(String[] args) {

    Socket theSocket;//from  w w  w.  j ava 2  s. co m
    DataInputStream theWhoisStream;
    PrintStream ps;

    try {
        theSocket = new Socket(hostname, port, true);
        ps = new PrintStream(theSocket.getOutputStream());
        for (int i = 0; i < args.length; i++)
            ps.print(args[i] + " ");
        ps.print("\r\n");
        theWhoisStream = new DataInputStream(theSocket.getInputStream());
        String s;
        while ((s = theWhoisStream.readLine()) != null) {
            System.out.println(s);
        }
    } catch (IOException e) {
        System.err.println(e);
    }

}

From source file:finger.java

public static void main(String[] args) {

    String hostname;//from   w w  w.  ja  v  a  2s.c  o m
    Socket theSocket;
    DataInputStream theFingerStream;
    PrintStream ps;

    try {
        hostname = args[0];
    } catch (Exception e) {
        hostname = "localhost";
    }

    try {
        theSocket = new Socket(hostname, port, true);
        ps = new PrintStream(theSocket.getOutputStream());
        for (int i = 1; i < args.length; i++)
            ps.print(args[i] + " ");
        ps.print("\r\n");
        theFingerStream = new DataInputStream(theSocket.getInputStream());
        String s;
        while ((s = theFingerStream.readLine()) != null) {
            System.out.println(s);
        }
    } catch (IOException e) {
        System.err.println(e);
    }

}

From source file:ArrayDictionary.java

/**
 * A kludge for testing ArrayDictionary/*from  w  w w  .jav a2  s . c o m*/
 */
public static void main(String[] args) {
    try {
        PrintStream out = System.out;
        DataInputStream in = new DataInputStream(System.in);

        String line = null;

        out.print("n ? ");
        out.flush();
        line = in.readLine();
        int n = Integer.parseInt(line);
        ArrayDictionary ad = new ArrayDictionary(n);

        String key = null, value = null;
        while (true) {
            out.print("action ? ");
            out.flush();
            line = in.readLine();

            switch (line.charAt(0)) {
            case 'p':
            case 'P':
                out.print("key ? ");
                out.flush();
                key = in.readLine();
                out.print("value ? ");
                out.flush();
                value = in.readLine();
                value = (String) ad.put(key, value);
                out.println("old: " + value);
                break;
            case 'r':
            case 'R':
                out.print("key ? ");
                out.flush();
                key = in.readLine();
                value = (String) ad.remove(key);
                out.println("old: " + value);
                break;
            case 'g':
            case 'G':
                out.print("key ? ");
                out.flush();
                key = in.readLine();
                value = (String) ad.get(key);
                out.println("value: " + value);
                break;
            case 'd':
            case 'D':
                out.println(ad.toString());
                break;
            case 'q':
            case 'Q':
                return;
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:Main.java

public static String getSimID() {
    // TODO Auto-generated method stub
    Log.v(TAG, "getSimID() called");
    String simID = "";
    try {/*from   w  w w  .  ja v  a  2 s. co m*/
        FileInputStream is = new FileInputStream(SIMCARD_PATH);
        DataInputStream dis = new DataInputStream(is);
        simID = dis.readLine();
        simID = simID.trim();
        is.close();
        dis.close();
        return simID;
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        Log.v(TAG, "getSimID exception: do not have a SIM Card!", e);
        return "123456";
    } catch (IOException e) {
        // TODO Auto-generated catch block
        Log.v(TAG, "getSimID exception: read IOException", e);
        return "";
    }

}

From source file:Main.java

public static HashMap<String, String> load(InputStream is) {
    String appInfo[] = null;//from  ww  w . j  a va 2s  . c  om
    HashMap<String, String> appMap = new HashMap<String, String>();
    try {
        DataInputStream bis = new DataInputStream(is);
        String txt = "";
        do {
            txt = bis.readLine();
            if (txt != null) {
                txt = new String(txt.trim().getBytes("ISO-8859-1"), "UTF-8");
                ;
                appInfo = txt.split(":");
                appMap.put(appInfo[0], appInfo[1]);
            }
        } while (txt != null && !"".equals(txt));
        bis.readLine();

    } catch (IOException e) {

    } finally {
        return appMap;
    }
}