Example usage for java.io InputStream read

List of usage examples for java.io InputStream read

Introduction

In this page you can find the example usage for java.io InputStream read.

Prototype

public abstract int read() throws IOException;

Source Link

Document

Reads the next byte of data from the input stream.

Usage

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    URL url = new URL("http://www.x.com");
    URLConnection urlc = url.openConnection();
    urlc.setRequestProperty("User-Agent", "Mozilla 5.0 (Windows; U; " + "Windows NT 5.1; en-US; rv:1.8.0.11) ");

    InputStream is = urlc.getInputStream();
    int c;//from ww w.  j av  a  2s . c o m
    while ((c = is.read()) != -1)
        System.out.print((char) c);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String command = "ls";
    Process child = Runtime.getRuntime().exec(command);

    InputStream in = child.getInputStream();
    int c;/*  w  ww.  j  a va  2s  .c om*/
    while ((c = in.read()) != -1) {
        System.out.println(((char) c));
    }
    in.close();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String command = "ls";
    Process child = Runtime.getRuntime().exec(command);

    InputStream in = child.getInputStream();
    int c;/*from w  w  w. ja v  a2  s .c  om*/
    while ((c = in.read()) != -1) {
        System.out.println((char) c);
    }
    in.close();
}

From source file:Main.java

public static void main(String[] args) throws IOException {
    ZipFile zf = new ZipFile("a.zip");
    Enumeration e = zf.entries();
    while (e.hasMoreElements()) {
        ZipEntry ze = (ZipEntry) e.nextElement();
        FileOutputStream fout = new FileOutputStream(ze.getName());
        InputStream in = zf.getInputStream(ze);
        for (int c = in.read(); c != -1; c = in.read()) {
            fout.write(c);/*  w  w w .  jav a 2 s. c  o m*/
        }
        in.close();
        fout.close();
    }
}

From source file:MainClass.java

public static void main(String[] args) throws IOException {
    ZipFile zf = new ZipFile(args[0]);
    Enumeration e = zf.entries();
    while (e.hasMoreElements()) {
        ZipEntry ze = (ZipEntry) e.nextElement();
        System.out.println("Unzipping " + ze.getName());
        FileOutputStream fout = new FileOutputStream(ze.getName());
        InputStream in = zf.getInputStream(ze);
        for (int c = in.read(); c != -1; c = in.read()) {
            fout.write(c);//from w  w  w.  java  2s  . c  om
        }
        in.close();
        fout.close();
    }
}

From source file:Run2.java

public static void main(String[] args) throws java.io.IOException {
    if (args.length != 1) {
        System.err.println("usage: java Run pathname");
        return;//w  w w .  j a v  a 2  s  .c  o m
    }

    Process p = Runtime.getRuntime().exec(args[0]);

    InputStream is = p.getInputStream();
    int b;
    while ((b = is.read()) != -1)
        System.out.print((char) b);

    try {
        System.out.println("Exit status = " + p.waitFor());
    } catch (InterruptedException e) {
    }
}

From source file:Main.java

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

    int i;// w  w  w .  j  a  v a2s  . c  om

    InputStream is = new FileInputStream("C://test.txt");

    while ((i = is.read()) != -1) {
        // converts int to char
        char c = (char) i;

        System.out.println("Character Read: " + c);

        // skip one byte
        is.skip(1);
    }
    is.close();
}

From source file:Main.java

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

    Vector theStreams = new Vector();

    for (int i = 0; i < args.length; i++) {
        FileInputStream fin = new FileInputStream(args[i]);
        theStreams.addElement(fin);/*from  w  w  w  .j  av  a 2  s  .  c o m*/
    }

    InputStream in = new SequenceInputStream(theStreams.elements());
    for (int i = in.read(); i != -1; i = in.read()) {
        System.out.write(i);
    }
}

From source file:Time867.java

public static void main(String[] args) {
    String hostname = "tock.usno.navy.mil";
    if (args.length == 1)
        hostname = args[0];//from   w  ww .j  av a  2  s.  c o m
    try {
        int c;
        Socket sock = new Socket(hostname, 13);
        InputStream is = sock.getInputStream();
        do {
            c = is.read();
            if (c != -1)
                System.out.print((char) c);
        } while (c != -1);
    } catch (IOException e) {
        System.out.println(e);
    }
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String driverName = "com.jnetdirect.jsql.JSQLDriver";
    Class.forName(driverName);/*from   ww  w .  ja va 2s  . com*/

    String serverName = "127.0.0.1";
    String portNumber = "1433";
    String mydatabase = serverName + ":" + portNumber;
    String url = "jdbc:JSQLConnect://" + mydatabase;
    String username = "username";
    String password = "password";

    Connection connection = DriverManager.getConnection(url, username, password);
    Statement stmt = connection.createStatement();
    ResultSet rs = stmt.executeQuery("SELECT col_blob FROM mysql_all_table");

    if (rs.next()) {
        Blob blob = rs.getBlob("col_blob");
        long blobLength = blob.length();

        int pos = 1; // position is 1-based
        int len = 10;
        byte[] bytes = blob.getBytes(pos, len);

        InputStream is = blob.getBinaryStream();
        int b = is.read();
    }
}