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 {
    SequenceInputStream inStream;
    FileInputStream f1 = new FileInputStream("ByteArrayIOApp.java");
    FileInputStream f2 = new FileInputStream("FileIOApp.java");
    inStream = new SequenceInputStream(f1, f2);
    boolean eof = false;
    int byteCount = 0;
    while (!eof) {
        int c = inStream.read();
        if (c == -1)
            eof = true;//from  ww w . j a va 2  s  .c  om
        else {
            System.out.print((char) c);
            ++byteCount;
        }
    }
    System.out.println(byteCount + " bytes were read");
    inStream.close();
    f1.close();
    f2.close();
}

From source file:MainClass.java

public static void main(String[] args) throws IOException {
    FileInputStream fin = new FileInputStream(args[0]);
    System.out.println(args[0] + ":\t" + getCRC32(fin));
    fin.close();//w  w w .  j a v  a  2 s  . co  m
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String fontFileName = "yourfont.ttf";
    InputStream is = new FileInputStream(fontFileName);

    Font ttfBase = Font.createFont(Font.TRUETYPE_FONT, is);

    Font ttfReal = ttfBase.deriveFont(Font.BOLD, AffineTransform.getRotateInstance(0.5));
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String fontFileName = "yourfont.ttf";
    InputStream is = new FileInputStream(fontFileName);

    Font ttfBase = Font.createFont(Font.TRUETYPE_FONT, is);

    Font ttfReal = ttfBase.deriveFont(AffineTransform.getRotateInstance(0.5));
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    MappedByteBuffer in = new FileInputStream("test.txt").getChannel().map(FileChannel.MapMode.READ_ONLY, 0,
            LENGTH);//  w w  w  .  j a v  a 2  s  .co m
    int i = 0;
    while (i < LENGTH)
        System.out.print((char) in.get(i++));
    System.out.println((char) in.get(i++));
}

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);
    boolean eof = false;
    int byteCount = 0;
    System.out.println(inStream.available());
    while (!eof) {
        int c = inStream.read();
        if (c == -1)
            eof = true;/*  w w w  .  j av a  2  s. c  o m*/
        else {
            System.out.print((char) c);
            ++byteCount;
        }
    }
    System.out.println(inStream.available());
    System.out.println(byteCount + " bytes were read");
    inStream.close();
    f1.close();
    f2.close();
}

From source file:Main.java

public static void main(String[] args) {
    File fileObject = new File("person.ser");

    try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream(fileObject))) {

        Person p1 = (Person) ois.readObject();
        Person p2 = (Person) ois.readObject();
        Person p3 = (Person) ois.readObject();

        System.out.println(p1);// w w  w. j  av a  2  s.c o m
        System.out.println(p2);
        System.out.println(p3);

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

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

    InputStream fin = new FileInputStream("a.dat");
    OutputStream fout = new FileOutputStream("a.dat.gz");
    GZIPOutputStream gzout = new GZIPOutputStream(fout);
    for (int c = fin.read(); c != -1; c = fin.read()) {
        gzout.write(c);//  w ww  .jav  a 2s.  c om
    }
    gzout.close();
}

From source file:ObjectReader.java

public static void main(String[] arguments) {
    try {/*from w  w  w.  ja v  a2  s. co m*/
        FileInputStream fi = new FileInputStream("message.obj");
        ObjectInputStream oi = new ObjectInputStream(fi);
        Message mess = (Message) oi.readObject();
        System.out.println("Message:\n");
        System.out.println("From: " + mess.from);
        System.out.println("To: " + mess.to);
        System.out.println("Date: " + mess.when + "\n");
        for (int i = 0; i < mess.lineCount; i++)
            System.out.println(mess.text[i]);
        oi.close();
    } catch (Exception e) {
        System.out.println("Error " + e.toString());
    }
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    FileInputStream fis = new FileInputStream("test");
    MessageDigest md = MessageDigest.getInstance("SHA");
    DigestInputStream dis = new DigestInputStream(fis, md);
    ObjectInputStream ois = new ObjectInputStream(dis);
    Object o = ois.readObject();//from www .ja  v a 2  s.co 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);
    dis.on(false);
    o = ois.readObject();
    if (!(o instanceof byte[])) {
        System.out.println("Unexpected data in file");
        System.exit(-1);
    }
    byte origDigest[] = (byte[]) o;
    System.out.println(MessageDigest.isEqual(md.digest(), origDigest));
}