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 {

    FileInputStream fin = new FileInputStream(args[0]);
    GZIPInputStream gzin = new GZIPInputStream(fin);
    ReadableByteChannel in = Channels.newChannel(gzin);

    WritableByteChannel out = Channels.newChannel(System.out);
    ByteBuffer buffer = ByteBuffer.allocate(65536);
    while (in.read(buffer) != -1) {
        buffer.flip();/*  w w  w .  j ava2 s  .co  m*/
        out.write(buffer);
        buffer.clear();
    }
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    FileInputStream is = new FileInputStream("your.keystore");

    KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
    keystore.load(is, "my-keystore-password".toCharArray());

    String alias = "myalias";
    Certificate cert = keystore.getCertificate(alias);

    File file = null;//w  w w.j a  v a  2  s  . c  o m
    byte[] buf = cert.getEncoded();

    FileOutputStream os = new FileOutputStream(file);
    os.write(buf);
    os.close();

    Writer wr = new OutputStreamWriter(os, Charset.forName("UTF-8"));
    wr.write(new sun.misc.BASE64Encoder().encode(buf));
    wr.flush();

}

From source file:Main.java

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

    byte b = 66;//w ww  .  j  a v  a2  s  . c o  m
    int i = 0;
    FileOutputStream fos = new FileOutputStream("C://test.txt");

    fos.write(b);

    fos.flush();

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

    // read till the end of the file
    while ((i = fis.read()) != -1) {
        // convert integer to character
        char c = (char) i;

        System.out.print(c);
    }

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String zipname = "data.zip";
    FileInputStream fis = new FileInputStream(zipname);
    ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis));
    ZipEntry entry;/*from  w  w  w  .  j  a v  a2 s .  co m*/

    while ((entry = zis.getNextEntry()) != null) {
        System.out.println("Unzipping: " + entry.getName());

        int size;
        byte[] buffer = new byte[2048];

        FileOutputStream fos = new FileOutputStream(entry.getName());
        BufferedOutputStream bos = new BufferedOutputStream(fos, buffer.length);

        while ((size = zis.read(buffer, 0, buffer.length)) != -1) {
            bos.write(buffer, 0, size);
        }
        bos.flush();
        bos.close();
    }
    zis.close();
    fis.close();
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    String zipname = "data.txt.gz";
    String source = "data.txt.gz";
    GZIPInputStream zipin;//  w ww  . ja  v  a  2 s  . c  om

    FileInputStream in = new FileInputStream(zipname);
    zipin = new GZIPInputStream(in);

    byte[] buffer = new byte[sChunk];
    // decompress the file
    FileOutputStream out = new FileOutputStream(source);
    int length;
    while ((length = zipin.read(buffer, 0, sChunk)) != -1)
        out.write(buffer, 0, length);
    out.close();

    zipin.close();
}

From source file:Main.java

public static void main(String[] args) throws IOException {
    Deflater def = new Deflater();
    byte[] input = new byte[1024];
    byte[] output = new byte[1024];

    FileInputStream fin = new FileInputStream("a.dat");
    FileOutputStream fout = new FileOutputStream("b.dat");

    int numRead = fin.read(input);

    def.setInput(input, 0, numRead);//from   ww  w  .ja  va  2s  . c om

    while (!def.needsInput()) {
        int numCompressedBytes = def.deflate(output, 0, output.length);
        if (numCompressedBytes > 0) {
            fout.write(output, 0, numCompressedBytes);
        }
    }
    def.finish();
    fin.close();
    fout.flush();
    fout.close();
    def.reset();
}

From source file:MainClass.java

public static void main(String[] args) {

    for (int i = 0; i < args.length; i++) {
        try {/*from  w ww .  j  a v a 2 s .  c  o m*/
            FileInputStream fin = new FileInputStream(args[i]);
            FileOutputStream fout = new FileOutputStream(args[i] + DEFLATE_SUFFIX);
            DeflaterOutputStream dos = new DeflaterOutputStream(fout);
            for (int c = fin.read(); c != -1; c = fin.read()) {
                dos.write(c);
            }
            dos.close();
            fin.close();
        } catch (IOException ex) {
            System.err.println(ex);
        }
    }
}

From source file:Main.java

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

    byte b = 66;/*from ww  w.j ava 2 s.  co m*/
    int i = 0;
    FileOutputStream fos = new FileOutputStream("C://test.txt", true);

    fos.write(b);

    fos.flush();

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

    // read till the end of the file
    while ((i = fis.read()) != -1) {
        // convert integer to character
        char c = (char) i;

        System.out.print(c);
    }

}

From source file:Main.java

public static void main(String[] args) {

    for (int i = 0; i < args.length; i++) {
        if (args[i].toLowerCase().endsWith(".dfl")) {
            try {
                FileInputStream fin = new FileInputStream(args[i]);
                InflaterInputStream iis = new InflaterInputStream(fin);
                FileOutputStream fout = new FileOutputStream(args[i].substring(0, args[i].length() - 4));
                for (int c = iis.read(); c != -1; c = iis.read()) {
                    fout.write(c);/*from w ww . j  a  va  2  s.  c o m*/
                }
                fout.close();
            } catch (IOException ex) {
                System.err.println(ex);
            }
        } else {
            System.err.println(args[i] + " does not appear to be a deflated file.");
        }
    }
}

From source file:Main.java

public static void main(String[] args) {
    FTPClient client = new FTPClient();
    FileInputStream fis = null;//from  w ww.j  a va2 s .  c  o  m

    client.connect("ftp.domain.com");
    client.login("admin", "secret");

    String filename = "Touch.dat";
    fis = new FileInputStream(filename);
    client.storeFile(filename, fis);
    client.logout();
    fis.close();
}