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:ShowFile.java

public static void main(String args[]) throws IOException {
    int i;//  ww  w . j  a va2  s  .c om
    FileInputStream fin;

    try {
        fin = new FileInputStream(args[0]);
    } catch (FileNotFoundException e) {
        System.out.println("File Not Found");
        return;
    } catch (ArrayIndexOutOfBoundsException e) {
        System.out.println("Usage: ShowFile File");
        return;
    }
    do {
        i = fin.read();
        if (i != -1)
            System.out.print((char) i);
    } while (i != -1);

    fin.close();
}

From source file:Main.java

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

    monitor = new ProgressMonitorInputStream(null, "Loading ", new FileInputStream("fileName.txt"));

    while (monitor.available() > 0) {
        byte[] data = new byte[38];
        monitor.read(data);/*w  w  w  . j ava 2 s  .  c  o  m*/
        System.out.write(data);
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    DataInputStream dis = new DataInputStream(new BufferedInputStream(new FileInputStream("temp.tmp")));
    for (int i = 0; i < 10; i++)
        dis.readInt();/* w  w  w.ja v  a  2s . c o m*/
    dis.close();

}

From source file:ZipReader.java

public static void main(String[] args) throws Exception {
    ZipInputStream zis = null;//  www  . j a  va 2 s . c o  m

    FileInputStream fis = new FileInputStream(args[0]);
    zis = new ZipInputStream(fis);

    ZipEntry ze;

    while ((ze = zis.getNextEntry()) != null)
        System.out.println(
                ze.getName() + "  [" + ze.getSize() + "]  [" + new Date(ze.getTime()).toString() + "]");
}

From source file:Main.java

public static void main(String[] args) throws IOException {
    DataInputStream dis = new DataInputStream(new BufferedInputStream(new FileInputStream("temp.tmp")));
    for (int i = 0; i < 10; i++)
        dis.readInt();//from  ww w.  java 2 s.co  m
    dis.close();

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    BufferedInputStream fin = new BufferedInputStream(new FileInputStream("in.dat"));
    BufferedOutputStream fout = new BufferedOutputStream(new FileOutputStream("out.dat"));
    int i;//www .  j  ava 2 s.  co m
    do {
        i = fin.read();
        if (i != -1)
            fout.write(i);
    } while (i != -1);
    fin.close();
    fout.close();
}

From source file:Main.java

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

    Scanner scanner = new Scanner(new FileInputStream("c:/text.txt").getChannel(),
            StandardCharsets.UTF_8.name());

    System.out.println(scanner.nextLine());

    // change the radix of the scanner
    scanner.useRadix(32);//w w  w .  ja va 2 s .  co m

    // display the new radix
    System.out.println(scanner.radix());

    scanner.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    FileChannel in = new FileInputStream("source.txt").getChannel(),
            out = new FileOutputStream("target.txt").getChannel();
    ByteBuffer buffer = ByteBuffer.allocate(BSIZE);
    while (in.read(buffer) != -1) {
        buffer.flip();//from w  ww.j a  va 2 s. c om
        out.write(buffer);
        buffer.clear();
    }
}

From source file:Main.java

public static void main(String[] args) throws IOException {
    Properties properties = new Properties();
    try (InputStream input = new FileInputStream("test.properties")) {
        properties.load(input);//from   w  ww  .jav  a2 s  .  co  m
    }

    for (String key : properties.stringPropertyNames()) {
        System.out.println(key + " = '" + properties.get(key) + "'");
    }
}

From source file:Main.java

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

    InputStream is = new FileInputStream("c:\\test.txt");

    DataInputStream dis = new DataInputStream(is);

    int count = is.available();

    byte[] bs = new byte[count];

    dis.read(bs);//from w ww . j  a va  2  s.com

    for (byte b : bs) {
        char c = (char) b;
        System.out.print(c);
    }

}