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 {

    FileInputStream is = new FileInputStream("c:/test.txt");
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    BufferedOutputStream bos = new BufferedOutputStream(baos);

}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    FileInputStream fis = new FileInputStream("test");
    ObjectInputStream ois = new ObjectInputStream(fis);
    Object o = ois.readObject();/*from www .  j  a v a2s .c  o m*/
    if (!(o instanceof String)) {
        System.out.println("Unexpected data in file");
        System.exit(-1);
    }
    String data = (String) o;
    System.out.println("Got message " + data);
    o = ois.readObject();
    if (!(o instanceof byte[])) {
        System.out.println("Unexpected data in file");
        System.exit(-1);
    }
    byte origDigest[] = (byte[]) o;
    byte pass[] = "aaa".getBytes();
    byte buf[] = data.getBytes();
    MessageDigest md = MessageDigest.getInstance("SHA");
    md.update(pass);
    md.update(buf);
    byte digest1[] = md.digest();
    md.update(pass);
    md.update(digest1);
    System.out.println(MessageDigest.isEqual(md.digest(), origDigest));
}

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);

    char[] cbuf = new char[is.available()];

    br.read(cbuf, 2, 10);/*from  ww  w . ja va2 s .  co  m*/

    for (char c : cbuf) {
        if (c == (char) 0) {
            c = '*';
        }
        // prints characters
        System.out.print(c);
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    File file = new File("C:/ReadFile.txt");
    FileInputStream fin = new FileInputStream(file);

    BufferedInputStream bin = new BufferedInputStream(fin);
    while (bin.available() > 0) {
        System.out.println((char) bin.read());
    }/*from   w  w  w. j a  v a  2 s  .  com*/
    bin.close();
}

From source file:Main.java

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

    int i = 0;/*w w w  .  jav a  2  s. com*/

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

    // read till the end of the file
    while ((i = fis.read()) != -1) {
        // get file channel
        FileChannel fc = fis.getChannel();

        // get channel position
        long pos = fc.position();

        char c = (char) i;

        System.out.println("No of bytes read: " + pos);
        System.out.println("Char read: " + c);
    }
}

From source file:Main.java

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

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

    // input stream reader is closed
    isr.close();//from w w w  . j a va 2 s .c o  m
    System.out.print("close() invoked");

    // read() called after closed method
    int i = isr.read();
    char c = (char) i;
    System.out.println(c);

}

From source file:Main.java

public static void main(String args[]) throws IOException {
    SequenceInputStream inStream;
    FileInputStream f1 = new FileInputStream("ByteArrayIOApp.java");
    FileInputStream f2 = new FileInputStream("FileIOApp.java");
    inStream = new SequenceInputStream(f1, f2);

    byte[] arrayBytes = new byte[100];
    int c = inStream.read(arrayBytes, 10, 10);

    inStream.close();/*  w ww. j av  a  2 s . com*/
    f1.close();
    f2.close();
}

From source file:Main.java

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

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

    // input stream reader is closed
    isr.close();/*from   ww w.  java 2  s.  c  om*/
    System.out.print("close() invoked");

    // read() called after closed method
    int i = isr.read();
    char c = (char) i;
    System.out.println(c);

}

From source file:Main.java

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

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

    // input stream reader is closed
    isr.close();//from   w w  w .  j av a 2  s  .co m
    System.out.print("close() invoked");

    // read() called after closed method
    int i = isr.read();
    char c = (char) i;
    System.out.println(c);

}

From source file:Main.java

public static void main(String args[]) throws IOException {
    FileInputStream fis = new FileInputStream("FileChannelExample.java");
    FileChannel fc = fis.getChannel();

    ByteBuffer bb = ByteBuffer.allocate((int) fc.size());

    fc.read(bb);//from  w w w .ja va  2 s.co m
    bb.flip();

    String fileContent = new String(bb.array());

    fc.close();
    fc = null;

    System.out.println("fileContent = " + fileContent);
}