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 Exception {

    int i;/* w w w . jav a 2s.c o m*/

    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:BufferedInputStreamDemo.java

public static void main(String args[]) throws Exception {
    FileInputStream fis = new FileInputStream(args[0]);

    BufferedInputStream bis = new BufferedInputStream(fis);

    int i;/*from   ww w .  ja  v a2  s. c  o m*/
    while ((i = bis.read()) != -1) {
        System.out.println(i);
    }

    fis.close();
}

From source file:FileSplitter.java

public static void main(String args[]) throws Exception {
    FileInputStream fis = new FileInputStream(args[0]);
    int size = 1024;
    byte buffer[] = new byte[size];

    int count = 0;
    while (true) {
        int i = fis.read(buffer, 0, size);
        if (i == -1)
            break;

        String filename = args[1] + count;
        FileOutputStream fos = new FileOutputStream(filename);
        fos.write(buffer, 0, i);/*from  w  w  w  .j  a va2 s .  c o m*/
        fos.flush();
        fos.close();

        ++count;
    }
}

From source file:Main.java

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

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

    // input stream is converted to buffered input stream
    BufferedInputStream bis = new BufferedInputStream(is);

}

From source file:Main.java

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

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

    // input stream is converted to buffered input stream
    BufferedInputStream bis = new BufferedInputStream(is, 200);

}

From source file:Main.java

public static void main(String[] args) throws IOException {
    FileInputStream fis = new FileInputStream(new File("C://test.txt"));

    // skip bytes from file input stream
    fis.skip(4);/*from   w w w.j  av  a 2s .  c o m*/

    // read bytes from this stream
    int i = fis.read();

    // converts integer to character
    char c = (char) i;
    System.out.print("Character read: " + c);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    FileInputStream fin = new FileInputStream("myfile.dat");

    DataInputStream din = new DataInputStream(fin);
    while (true) {
        int theNumber = din.readInt();
        //double theNumber = din.readDouble();
        //System.out.println(din.readUTF());
        //boolean b = din.readBoolean();
        byte b = din.readByte();
        System.out.println("byte : " + b);
        System.out.println(theNumber);

        char ch = din.readChar();
        System.out.println("Char : " + ch);
        float f = din.readFloat();
        System.out.println("float : " + f);
        long l = din.readLong();
        System.out.println("long : " + l);

    }//from   www.  j a va2  s  . c  o m
}

From source file:ByteReader.java

public static void main(String[] arguments) {
    try {// w  w  w .ja  v  a  2s .  co  m
        FileInputStream file = new FileInputStream("class.dat");
        boolean eof = false;
        int count = 0;
        while (!eof) {
            int input = file.read();
            System.out.print(input + " ");
            if (input == -1)
                eof = true;
            else
                count++;
        }
        file.close();
        System.out.println("\nBytes read: " + count);
    } catch (IOException e) {
        System.out.println("Error - " + e.toString());
    }
}

From source file:Main.java

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

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

    System.out.println("Characters printed:");
    // create new buffered reader

    // reads and prints BufferedReader
    System.out.println((char) is.read());
    System.out.println((char) is.read());

    // mark invoked at this position
    is.mark(0);//from  w w w.j a  va 2 s  .  c o  m
    System.out.println("mark() invoked");
    System.out.println((char) is.read());
    System.out.println((char) is.read());

    // reset() repositioned the stream to the mark
    if (is.markSupported()) {
        is.reset();
        System.out.println("reset() invoked");
        System.out.println((char) is.read());
        System.out.println((char) is.read());
    } else {
        System.out.print("InputStream does not support reset()");
    }
    is.close();
}

From source file:Main.java

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

    FileInputStream is = new FileInputStream(new File("your"));

    CertificateFactory cf = CertificateFactory.getInstance("X.509");
    java.security.cert.Certificate cert = cf.generateCertificate(is);
}