Example usage for java.io FileInputStream read

List of usage examples for java.io FileInputStream read

Introduction

In this page you can find the example usage for java.io FileInputStream read.

Prototype

public int read() throws IOException 

Source Link

Document

Reads a byte of data from this input stream.

Usage

From source file:Main.java

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

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

    int i = fis.read();

    char c = (char) i;

    System.out.println(c);/*w  w w.j  a  v a2  s  . c  o  m*/

    // close file input stream
    fis.close();

}

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;/*w  ww . j a  v a  2s  . 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[] argv) throws Exception {
    FileInputStream file = null;
    file = new FileInputStream("main.java");
    byte x = (byte) file.read();
    System.out.println(x);//from  w  w  w  .  j a v a 2  s.c  om
    file.close();

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    FileInputStream fin = new FileInputStream("test.txt");
    int i;//from   w  w  w. j av a  2 s  . com
    do {
        i = fin.read();
        if (i != -1)
            System.out.printf("%02X ", i);
    } while (i != -1);
    fin.close();
}

From source file:Main.java

public static void main(String[] args) throws IOException {
    FileInputStream fin = new FileInputStream("a.zip");
    Checksum cs = new CRC32();
    for (int b = fin.read(); b != -1; b = fin.read()) {
        cs.update(b);//w ww.j  a v  a  2 s  .  c o  m
    }
    System.out.println(cs.getValue());
    fin.close();
}

From source file:Main.java

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

    byte[] buffer = { 65, 66, 67, 68, 69 };
    int i = 0;/*w  w  w.  ja v  a2  s  .  co m*/
    OutputStream os = new FileOutputStream("C://test.txt");
    FilterOutputStream fos = new FilterOutputStream(os);

    // writes buffer to the output stream
    fos.write(buffer, 2, 3);

    // forces byte contents to written out to the stream
    fos.flush();

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

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

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

From source file:Main.java

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

    byte[] buffer = { 65, 66, 67, 68, 69 };
    int i = 0;/* w w  w .ja  va  2s . c o  m*/

    OutputStream os = new FileOutputStream("C://test.txt");
    FilterOutputStream fos = new FilterOutputStream(os);

    // writes buffer to the output stream
    fos.write(buffer);

    // forces byte contents to written out to the stream
    fos.flush();

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

    while ((i = fis.read()) != -1) {
        // converts integer to the character
        char c = (char) i;
        System.out.println("Character read: " + c);
    }
    fos.close();
    fis.close();
}

From source file:Main.java

public static void main(String[] args) throws IOException {
    String outputFile = "a.zip";
    int level = 9;
    FileOutputStream fout = new FileOutputStream(outputFile);
    ZipOutputStream zout = new ZipOutputStream(fout);
    zout.setLevel(level);/*from  w w  w .j  ava  2  s .  c  o m*/

    ZipEntry ze = new ZipEntry("a.zip");
    FileInputStream fin = new FileInputStream("b.dat");
    zout.putNextEntry(ze);
    for (int c = fin.read(); c != -1; c = fin.read()) {
        zout.write(c);
    }
    fin.close();
    zout.close();
}

From source file:FileInputStreamDemo.java

public static void main(String args[]) throws Exception {
    FileInputStream fis = new FileInputStream(args[0]);

    // Read and display data
    int i;/* w  w w.j av  a 2s. c om*/
    while ((i = fis.read()) != -1) {
        System.out.println(i);
    }

    fis.close();

}

From source file:Main.java

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

    OutputStream os = new FileOutputStream("C://test.txt");
    FilterOutputStream fos = new FilterOutputStream(os);

    fos.write(65);// w ww  . j ava 2s. c  o m

    // forces byte contents to written out to the stream
    fos.flush();

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

    // read byte
    int i = fis.read();

    // convert integer to characters
    char c = (char) i;

    System.out.print("Character read: " + c);
    fos.close();
    fis.close();
}