Example usage for java.io FileInputStream FileInputStream

List of usage examples for java.io FileInputStream FileInputStream

Introduction

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

Prototype

public FileInputStream(FileDescriptor fdObj) 

Source Link

Document

Creates a FileInputStream by using the file descriptor fdObj, which represents an existing connection to an actual file in the file system.

Usage

From source file:Main.java

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

    FileInputStream fis = new FileInputStream("C:/test.txt");
    LineNumberInputStream lnis = new LineNumberInputStream(fis);

    System.out.println((char) lnis.read());
    System.out.println((char) lnis.read());

    lnis.mark(0);//w  ww .  j  a v  a  2s. co  m
    System.out.println("mark() invoked");
    System.out.println((char) lnis.read());
    System.out.println((char) lnis.read());

    if (lnis.markSupported()) {
        lnis.reset();
        System.out.println("reset() invoked");
        System.out.println((char) lnis.read());
        System.out.println((char) lnis.read());
    }

}

From source file:MainClass.java

public static void main(String args[]) {
    try {//from   w  w  w . j  av  a2  s  .  co m

        FileInputStream fis = new FileInputStream("fileName.dat");

        // Create a data input stream
        DataInputStream dis = new DataInputStream(fis);

        // Read and display data
        System.out.println(dis.readBoolean());
        System.out.println(dis.readByte());
        System.out.println(dis.readChar());
        System.out.println(dis.readDouble());
        System.out.println(dis.readFloat());
        System.out.println(dis.readInt());
        System.out.println(dis.readLong());
        System.out.println(dis.readShort());

        // Close file input stream
        fis.close();
    } catch (Exception e) {
        System.out.println("Exception: " + e);
    }
}

From source file:Main.java

public static void main(String[] args) {
    String srcFile = "test.txt";
    try (BufferedInputStream bis = new BufferedInputStream(new FileInputStream(srcFile))) {
        // Read one byte at a time and display it
        byte byteData;
        while ((byteData = (byte) bis.read()) != -1) {
            System.out.print((char) byteData);
        }/* w ww .j av a 2 s . c o m*/
    } catch (Exception e2) {
        e2.printStackTrace();
    }
}

From source file:Main.java

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

    int i = 0;//from   www. j  a v  a 2  s  . c o  m

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

    // read till the end of the stream
    while ((i = is.read()) != -1) {
        // convert integer to character
        char c = (char) i;

        // print
        System.out.println("Character Read: " + c);
    }
    is.close();
}

From source file:Main.java

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

    int i;/*from   w  ww .  ja  v  a2  s  .  c o m*/

    FileInputStream fis = new FileInputStream("C:/test.txt");
    InputStreamReader isr = new InputStreamReader(fis);

    while ((i = isr.read()) != -1) {
        char c = (char) i;
        System.out.println("Character read: " + c);
        // true if the next read is guaranteed
        boolean bool = isr.ready();

        System.out.println("Ready to read: " + bool);
    }
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    FileInputStream fr = new FileInputStream("sdo.cer");
    CertificateFactory cf = CertificateFactory.getInstance("X509");
    X509Certificate c = (X509Certificate) cf.generateCertificate(fr);
    System.out.println("\tCertificate for: " + c.getSubjectDN());
    System.out.println("\tCertificate issued by: " + c.getIssuerDN());
    System.out.println("\tThe certificate is valid from " + c.getNotBefore() + " to " + c.getNotAfter());
    System.out.println("\tCertificate SN# " + c.getSerialNumber());
    System.out.println("\tGenerated with " + c.getSigAlgName());
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream("infilename"), "UTF8"));
    String str = in.readLine();/*from  ww w.ja v a2  s  . c  om*/
    System.out.println(str);
}

From source file:Main.java

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

    int i;/*from   ww  w.  j a  va 2 s.  c  om*/
    FileInputStream fis = new FileInputStream("C:/test.txt");
    LineNumberInputStream lnis = new LineNumberInputStream(fis);

    while ((i = lnis.read()) != -1) {
        char c = (char) i;

        System.out.println(c);

        lnis.skip(1);
    }

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    InputStream is = new FileInputStream("c:/test.txt");

    InputStreamReader isr = new InputStreamReader(is);

    BufferedReader br = new BufferedReader(isr);

    br.close();//from  w  ww.  j  a  v  a2 s  .  co  m

    // creates error
    br.read();

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    InputStream is = new FileInputStream("c:/test.txt");

    InputStreamReader isr = new InputStreamReader(is);

    BufferedReader br = new BufferedReader(isr);

    int value = 0;
    while ((value = br.read()) != -1) {
        char c = (char) value;
        System.out.println(c);//www  .  j a va 2  s.  com
    }
}