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 {

    ObjectOutputStream out = new ObjectOutputStream(
            new BufferedOutputStream(new FileOutputStream("file.data")));
    out.writeBoolean(true);//from  w ww  . ja  v  a2  s .  c o  m
    out.close();

    ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(new FileInputStream("file.data")));

    byte[] byteArray = new byte[10];
    in.read(byteArray);
    System.out.println(Arrays.toString(byteArray));
    in.close();
}

From source file:Main.java

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

    ObjectOutputStream out = new ObjectOutputStream(
            new BufferedOutputStream(new FileOutputStream("file.data")));
    out.writeFloat(1.234F);//  www.  j  ava  2 s  .co  m
    out.close();

    ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(new FileInputStream("file.data")));

    byte[] byteArray = new byte[10];
    in.read(byteArray);
    System.out.println(Arrays.toString(byteArray));
    in.close();
}

From source file:Main.java

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

    long[] l = { 1234567898765L, 12345678909876L };

    FileOutputStream fos = new FileOutputStream("c:\\test.txt");
    DataOutputStream dos = new DataOutputStream(fos);

    for (long j : l) {
        dos.writeLong(j);/*from ww w.  j ava2 s .  co  m*/
    }
    dos.flush();

    InputStream is = new FileInputStream("c:\\test.txt");
    DataInputStream dis = new DataInputStream(is);

    while (dis.available() > 0) {
        long k = dis.readLong();
        System.out.print(k);
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    XMLInputFactory inputFactory = XMLInputFactory.newInstance();
    XMLStreamReader reader = inputFactory.createXMLStreamReader(new FileInputStream(new File("test.xml")));
    System.out.println(countEvents(reader));

    reader = inputFactory.createXMLStreamReader(new FileInputStream(new File("test.xml")));

    StreamFilter filter = new ElementOnlyFilter();
    reader = inputFactory.createFilteredReader(reader, filter);

    System.out.println(countEvents(reader));
}

From source file:Main.java

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

    String[] s = { "Hello", "java2s.com!" };

    FileOutputStream fos = new FileOutputStream("c:\\test.txt");

    DataOutputStream dos = new DataOutputStream(fos);

    for (String j : s) {
        dos.writeUTF(j);/*from w  w w  .j av a 2s.c  o m*/
    }

    dos.flush();

    InputStream is = new FileInputStream("c:\\test.txt");

    DataInputStream dis = new DataInputStream(is);
    while (dis.available() > 0) {
        String k = dis.readUTF();
        System.out.print(k);
    }

}

From source file:Main.java

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

    byte[] buf = { 65, 66, 67, 68, 69, 70 };

    FileOutputStream fos = new FileOutputStream("c:\\test.txt");

    DataOutputStream dos = new DataOutputStream(fos);

    for (byte b : buf) {
        dos.writeChar(b);//w  ww .  j ava 2 s.  c  o m
    }
    dos.flush();

    InputStream is = new FileInputStream("c:\\test.txt");

    DataInputStream dis = new DataInputStream(is);

    while (dis.available() > 0) {
        char c = dis.readChar();
        System.out.print(c);
    }

}

From source file:Main.java

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

    ObjectOutputStream out = new ObjectOutputStream(
            new BufferedOutputStream(new FileOutputStream("file.data")));
    out.writeChars("java2s.com");
    out.close();/*www  .  j av  a2s  . co  m*/

    ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(new FileInputStream("file.data")));

    byte[] byteArray = new byte[10];
    in.read(byteArray);
    System.out.println(Arrays.toString(byteArray));
    in.close();
}

From source file:Main.java

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

    ObjectOutputStream out = new ObjectOutputStream(
            new BufferedOutputStream(new FileOutputStream("file.data")));
    out.writeBytes("java2s.com");
    out.close();/*from  ww w.j  a  v  a 2s .  co  m*/

    ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(new FileInputStream("file.data")));

    byte[] byteArray = new byte[10];
    in.read(byteArray);
    System.out.println(Arrays.toString(byteArray));
    in.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    FileOutputStream out = new FileOutputStream("test.txt");
    ObjectOutputStream oout = new ObjectOutputStream(out);

    // write something in the file
    oout.writeBoolean(true);// w  w w. ja  va 2 s .c  o  m
    oout.flush();
    oout.close();
    // create an ObjectInputStream for the file we created before
    ObjectInputStream ois = new ObjectInputStream(new FileInputStream("test.txt"));

    // read and print a boolean
    System.out.println(ois.readBoolean());
    ois.close();

}

From source file:Main.java

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

    ObjectOutputStream out = new ObjectOutputStream(
            new BufferedOutputStream(new FileOutputStream("file.data")));
    out.writeLong(1111111111111L);//  w ww.j  av a 2  s  .  c  om
    out.close();

    ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(new FileInputStream("file.data")));

    byte[] byteArray = new byte[10];
    in.read(byteArray);
    System.out.println(Arrays.toString(byteArray));
    in.close();
}