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[] argv) throws Exception {
    String source = "s.gzip";
    GZIPInputStream in = new GZIPInputStream(new FileInputStream(source));
    String target = "outfile";
    OutputStream out = new FileOutputStream(target);
    byte[] buf = new byte[1024];
    int len;/*  ww w . j a v  a  2s  .  c  om*/
    while ((len = in.read(buf)) > 0) {
        out.write(buf, 0, len);
    }
    in.close();
    out.close();
}

From source file:Main.java

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

    int i = 0;// w  w  w.j av a  2  s  . c  om

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

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

        System.out.print("Read: " + c);

        int j = fis.available();

        System.out.println("; Available bytes: " + j);
    }
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    // Create an input stream on a file
    InputStream is = new BufferedInputStream(new FileInputStream("output.xml"));

    // Import preference data

    Preferences.importPreferences(is);
}

From source file:Main.java

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

    // create input streams
    InputStream is = new FileInputStream("C://test.txt");
    FilterInputStream fis = new BufferedInputStream(is);

    // closes and releases the associated system resources
    fis.close();//from   w  w  w .j  a  va  2  s. co m

    // read is called after close() invocation
    fis.read();

}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    CertificateFactory cf = CertificateFactory.getInstance("X.509");
    FileInputStream in = new FileInputStream(args[0]);
    X509CRL crl = (X509CRL) cf.generateCRL(in);
    System.out.println("type = " + crl.getType());
    System.out.println("version = " + crl.getVersion());
    System.out.println("issuer = " + crl.getIssuerDN().getName());
    System.out.println("signing algorithm = " + crl.getSigAlgName());
    System.out.println("this update = " + crl.getThisUpdate());
    System.out.println("next update = " + crl.getNextUpdate());
    in.close();/* w w  w .  j a v  a  2s  .  com*/
}

From source file:Main.java

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

    byte[] buffer = new byte[6];

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

    // returns number of bytes read to buffer
    int i = fis.read(buffer, 2, 4);

    System.out.println("Number of bytes read: " + i);

    // for each byte in buffer
    for (byte b : buffer) {
        // converts byte to character
        char c = (char) b;

        // if byte is null
        if (b == 0) {
            c = '-';
        }//w w  w  . j  a  va 2 s. c  om
        System.out.println("Char read from buffer b: " + c);
    }

}

From source file:MainClass.java

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

    FileInputStream inFile = new FileInputStream(args[0]);
    FileOutputStream outFile = new FileOutputStream(args[1]);

    FileChannel inChannel = inFile.getChannel();
    FileChannel outChannel = outFile.getChannel();

    ByteBuffer buffer = ByteBuffer.allocate(1024 * 1024);
    int bytesRead = 0;
    while (bytesRead >= 0 || buffer.hasRemaining()) {
        if (bytesRead != -1)
            bytesRead = inChannel.read(buffer);
        buffer.flip();//from   www  . j  a v  a 2s. co  m
        outChannel.write(buffer);
        buffer.compact();
    }

    inChannel.close();
    outChannel.close();
}

From source file:Main.java

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

    int i = 0;/*from   w  w w.j a va  2 s  .com*/

    // create input streams
    InputStream is = new FileInputStream("C://test.txt");
    FilterInputStream fis = new BufferedInputStream(is);

    while ((i = fis.read()) != -1) {
        // converts integer to character
        char c = (char) i;

        // skips 3 bytes
        fis.skip(3);

        System.out.println("Character read: " + c);
    }

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    ZipInputStream inStream = new ZipInputStream(new FileInputStream("compressed.zip"));
    OutputStream outStream = new FileOutputStream("extracted.txt");

    byte[] buffer = new byte[1024];
    int read;//from  ww w.  ja  va2s.  c o  m
    ZipEntry entry;
    if ((entry = inStream.getNextEntry()) != null) {
        while ((read = inStream.read(buffer)) > 0) {
            outStream.write(buffer, 0, read);
        }
    }
    outStream.close();
    inStream.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    File aFile = new File("main.java");
    FileInputStream inFile = new FileInputStream(aFile);
    FileChannel inChannel = inFile.getChannel();
    ByteBuffer lengthBuf = ByteBuffer.allocate(8);
    while (true) {
        if (inChannel.read(lengthBuf) == -1) {
            break;
        }/* ww w .  j a  va2  s.  c  o  m*/
        lengthBuf.flip();
        int strLength = (int) lengthBuf.getDouble();
        ByteBuffer buf = ByteBuffer.allocate(2 * strLength + 8);
        if (inChannel.read(buf) == -1) {
            break;
        }
        buf.flip();
        byte[] strChars = new byte[2 * strLength];
        buf.get(strChars);
        System.out.println(strLength);
        System.out.println(ByteBuffer.wrap(strChars).asCharBuffer());
        System.out.println(buf.getLong());
        lengthBuf.clear();
    }
    inFile.close();
}