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 Exception {
    Properties config = new Properties();
    config.load(new FileInputStream("conf-file.pros"));

    Enumeration en = config.keys();
    while (en.hasMoreElements()) {
        String key = (String) en.nextElement();
        System.out.println(key + ":" + config.get(key));
    }//from ww w. jav a2 s .c om
}

From source file:Main.java

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

    int i = 0;// w w  w  .  j a v a  2s .c om
    // create new file input stream
    FileInputStream fis = new FileInputStream("C://test.txt");

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

From source file:Main.java

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

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

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

    // change the radix of the scanner
    scanner.useRadix(32);/* w  w  w.jav  a 2s  .c  o m*/

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

    scanner.close();
}

From source file:Main.java

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

    BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream("infilename"), "8859_1"));
    String str = in.readLine();/*from  w w  w  .j a  v  a  2  s.  c  om*/
    System.out.println(str);
}

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 length = dis.available();

    byte[] buf = new byte[length];

    dis.readFully(buf);//from  ww w .  j a v a2  s.  c o  m

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

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    ReadableByteChannel channel = new FileInputStream("infile.dat").getChannel();

    ByteBuffer buf = ByteBuffer.allocateDirect(10);

    int numRead = 0;
    while (numRead >= 0) {
        buf.rewind();// w  w w  .j  av a 2  s  .c om

        numRead = channel.read(buf);

        buf.rewind();

        for (int i = 0; i < numRead; i++) {
            byte b = buf.get();
        }
    }
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    ReadableByteChannel channel = new FileInputStream("infile").getChannel();

    ByteBuffer buf = ByteBuffer.allocateDirect(10);

    int numRead = 0;
    while (numRead >= 0) {
        buf.rewind();// w  ww.j  av a  2  s.c o  m

        numRead = channel.read(buf);

        buf.rewind();

        for (int i = 0; i < numRead; i++) {
            byte b = buf.get();
        }
    }
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    Properties p = new Properties();
    p.load(new FileInputStream("test.txt"));
    Enumeration e = p.propertyNames();

    for (; e.hasMoreElements();) {
        System.out.println(e.nextElement());

    }/*from   ww w .  j  av a  2 s.c om*/
}

From source file:Main.java

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

    int i;//www  . jav  a 2  s  .  c o  m
    FileInputStream fis = new FileInputStream("C:/test.txt");
    LineNumberInputStream lnis = new LineNumberInputStream(fis);

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

        if (i != 10) {
            System.out.println("Character read: " + c);

            int j = lnis.getLineNumber();
            System.out.println(" at line: " + j);
        }
    }

}

From source file:Main.java

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

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

    InputStreamReader isr = new InputStreamReader(is);

    BufferedReader br = new BufferedReader(isr);

    boolean bool = false;

    bool = br.markSupported();//  w  ww .j a v a 2 s  .  co  m

    System.out.println("Buffered reader supports mark : " + bool);

}