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 {
    Properties properties = new Properties();
    try {/*w w  w.j a v a 2s.  c o  m*/
        properties.load(new FileInputStream("filename.properties"));
    } catch (IOException e) {
    }
    String string = properties.getProperty("a.b");
    properties.setProperty("a.b", "new value");
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    ZipInputStream in = new ZipInputStream(new FileInputStream("source.zip"));
    OutputStream out = new FileOutputStream("target");
    byte[] buf = new byte[1024];
    int len;//ww  w. j av  a  2  s  .c  o  m
    while ((len = in.read(buf)) > 0) {
        out.write(buf, 0, len);
    }
    out.close();
    in.close();
}

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

    inChannel.transferTo(0, inChannel.size(), outChannel);

    inChannel.close();//from  www  . j  av  a  2s.  c  o m
    outChannel.close();
}

From source file:Main.java

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

    byte[] buffer = new byte[5];

    // new input stream created
    InputStream is = new FileInputStream("C://test.txt");

    System.out.println("Characters printed:");

    // read stream data into buffer
    is.read(buffer);/*  w  w w.  ja va  2 s  .  c om*/

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

        // prints character
        System.out.print(c);
    }
    is.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    BufferedInputStream is = new BufferedInputStream(new FileInputStream("a.exe"));
    byte[] bytes = new byte[1024];
    int len = 0;//from   w  ww  .java 2s . c  o  m

    while ((len = is.read(bytes)) >= 0) {
        new CRC32().update(bytes, 0, len);
    }
    is.close();
    System.out.println(Arrays.toString(bytes));

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    File file = new File("C:/String.txt");
    StringBuffer strContent = new StringBuffer();
    FileInputStream fin = new FileInputStream(file);
    int ch;//  www.ja va2 s  . co m
    while ((ch = fin.read()) != -1) {
        strContent.append((char) ch);
    }
    fin.close();
    System.out.println(strContent);
}

From source file:Main.java

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

    outStream.putNextEntry(new ZipEntry("test.txt"));

    byte[] buffer = new byte[1024];
    int bytesRead;

    while ((bytesRead = inStream.read(buffer)) > 0) {
        outStream.write(buffer, 0, bytesRead);
    }//from   w w w. j  a  v  a 2 s  .c om

    outStream.closeEntry();
    outStream.close();
    inStream.close();
}

From source file:Main.java

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

    InputStream iStream = new FileInputStream("c:/test.txt");

    // input stream converted to buffered input stream
    BufferedInputStream bis = new BufferedInputStream(iStream);

    // read and print characters one by one
    System.out.println((char) bis.read());
    System.out.println((char) bis.read());
    System.out.println((char) bis.read());

    // mark is set on the input stream
    bis.mark(0);/*from  w  w w . j  ava  2s  .  c  om*/
    System.out.println((char) bis.read());
    System.out.println("reset() invoked");

    // reset is called
    bis.reset();

    // read and print characters
    System.out.println((char) bis.read());
    System.out.println((char) bis.read());

}

From source file:Main.java

public static void main(String[] args) throws IOException {
    char[] cbuf = new char[5];

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

    // reads into the char buffer
    int i = isr.read(cbuf, 2, 3);

    // prints the number of characters
    System.out.println("Number of characters read: " + i);

    // for each character in the character buffer
    for (char c : cbuf) {
        // for empty character
        if (((int) c) == 0)
            c = '-';

        System.out.println(c);//ww w  .  j  a v  a2 s . c o m
    }
    isr.close();
}

From source file:Main.java

public static void main(String args[]) throws IOException {
    SequenceInputStream inStream;
    FileInputStream f1 = new FileInputStream("file1.java");
    FileInputStream f2 = new FileInputStream("file2.java");
    inStream = new SequenceInputStream(f1, f2);
    boolean eof = false;
    int byteCount = 0;
    while (!eof) {
        int c = inStream.read();
        if (c == -1)
            eof = true;/*from   w w  w  . j  av a 2s.  c  om*/
        else {
            System.out.print((char) c);
            ++byteCount;
        }
    }
    System.out.println(byteCount + " bytes were read");
    inStream.close();
    f1.close();
    f2.close();
}