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

public static void main(String[] args) throws Exception {
    long length = new File("test.txt").length();
    MappedByteBuffer in = new FileInputStream("test.txt").getChannel().map(FileChannel.MapMode.READ_ONLY, 0,
            length);/*  www  .ja  va  2s.c o  m*/
    int i = 0;
    while (i < length)
        System.out.print((char) in.get(i++));
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    File aFile = new File("C:/test.bin");
    FileInputStream inFile = new FileInputStream(aFile);
    FileChannel inChannel = inFile.getChannel();
    final int PRIMECOUNT = 6;
    ByteBuffer buf = ByteBuffer.allocate(8 * PRIMECOUNT);
    long[] primes = new long[PRIMECOUNT];
    while (inChannel.read(buf) != -1) {
        ((ByteBuffer) (buf.flip())).asLongBuffer().get(primes);
        for (long prime : primes) {
            System.out.printf("%10d", prime);
        }//from   ww  w . j a  va2  s.  c o  m
        buf.clear();
    }
    inFile.close();
}

From source file:FISTest.java

public static void main(String[] args) throws Exception {
    XMLInputFactory factory = XMLInputFactory.newInstance();
    FileInputStream fis = new FileInputStream("c.xml");
    XMLStreamReader reader = factory.createXMLStreamReader(fis);
    reader.close();//from w w w.jav  a2 s  .  c  om
    fis.close();

}

From source file:Main.java

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

    File f = new File("your.ttf");
    FileInputStream in = new FileInputStream(f);
    Font dynamicFont = Font.createFont(Font.TRUETYPE_FONT, in);
    Font dynamicFont32Pt = dynamicFont.deriveFont(32f);

    JLabel testLabel = new JLabel("Dynamically loaded font \"" + dynamicFont.getName() + "\"");
    testLabel.setFont(dynamicFont32Pt);/*  w  w  w.  ja  v a2s  .c  om*/
    JFrame frame = new JFrame("Font Loading Demo");
    frame.getContentPane().add(testLabel);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    // Create a manifest from a file
    InputStream fis = new FileInputStream("manifestfile");
    Manifest manifest = new Manifest(fis);

    // Construct a string version of a manifest
    StringBuffer sbuf = new StringBuffer();
    sbuf.append("Manifest-Version: 1.0\n");
    sbuf.append("\n");
    sbuf.append("Name: javax/swing/JScrollPane.class\n");
    sbuf.append("Java-Bean: True\n");

    // Convert the string to a input stream
    InputStream is = new ByteArrayInputStream(sbuf.toString().getBytes("UTF-8"));

    // Create the manifest
    manifest = new Manifest(is);
}

From source file:PropView.java

public static void main(String args[]) throws Exception {
    Properties properties = System.getProperties();
    properties.list(System.out);/*from  w ww.  j  ava  2 s  . com*/

    FileInputStream in = null;

    in = new FileInputStream(args[0]);
    properties.load(in);

    System.getProperties().list(System.out);
    System.out.println("\nValue of local.animal.defined is " + Boolean.getBoolean("local.animal.defined"));
    System.out.println("\nValue of local.animal.legcount is " + Integer.getInteger("local.animal.legcount"));
}

From source file:Main.java

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

    XMLDecoder decoder = new XMLDecoder(new BufferedInputStream(new FileInputStream("infilename.xml")));

    MyClass o = (MyClass) decoder.readObject();
    decoder.close();//from  w  w  w . j  av a 2s  . c  o m

    int prop = o.getProp(); // 1
    int[] props = o.getProps(); // [1, 2, 3]

}

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

    for (ByteBuffer buffer = ByteBuffer.allocate(1024 * 1024); inChannel.read(buffer) != -1; buffer.clear()) {
        buffer.flip();/*from w w w. j  a  va  2 s  .  co  m*/
        while (buffer.hasRemaining())
            outChannel.write(buffer);
    }

    inChannel.close();
    outChannel.close();
}

From source file:PrimeReader.java

public static void main(String[] arguments) {
    try {/* www .  j av  a2s. c  o m*/
        FileInputStream file = new FileInputStream("400primes.dat");
        BufferedInputStream buff = new BufferedInputStream(file);
        DataInputStream data = new DataInputStream(buff);

        try {
            while (true) {
                int in = data.readInt();
                System.out.print(in + " ");
            }
        } catch (EOFException eof) {
            buff.close();
        }
    } catch (IOException e) {
        System.out.println("Error - " + e.toString());
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    int i = 0;//from  w ww.  j a  va2 s. com

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

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

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

}