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[] a) {
    File aFile = new File("C:/myFile.txt");
    FileInputStream inputFile = null;
    try {/*from  w  w  w . ja v  a2  s . com*/
        inputFile = new FileInputStream(aFile);
    } catch (FileNotFoundException e) {
        e.printStackTrace(System.err);
        System.exit(1);
    }
}

From source file:Main.java

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

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

    BufferedInputStream bis = new BufferedInputStream(is);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    BufferedOutputStream bos = new BufferedOutputStream(baos);

    int value;//from  w  w  w.  j a v  a2 s.  com

    while ((value = bis.read()) != -1) {
        bos.write(value);
    }

    bos.flush();

    for (byte b : baos.toByteArray()) {

        char c = (char) b;
        System.out.println(c);
    }

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    File file = new File("c:\\a.bat");
    InputStream is = new FileInputStream(file);

    long length = file.length();
    if (length > Integer.MAX_VALUE) {
        System.out.println("File is too large");
    }/*ww w. ja va 2  s . c  o m*/

    byte[] bytes = new byte[(int) length];

    int offset = 0;
    int numRead = 0;
    while (numRead >= 0) {
        numRead = is.read(bytes, offset, bytes.length - offset);
        offset += numRead;
    }

    if (offset < bytes.length) {
        throw new IOException("Could not completely read file " + file.getName());
    }
    is.close();
    System.out.println(new String(bytes));
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String fromFileName = "from.txt";
    String toFileName = "to.txt";
    FileChannel in = new FileInputStream(fromFileName).getChannel();
    FileChannel out = new FileOutputStream(toFileName).getChannel();
    in.transferTo(0, (int) in.size(), out);
    in.close();/*from   w  ww  . j  av a 2  s  .  com*/
    out.close();
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    MessageDigest m = MessageDigest.getInstance("MD5");
    FileInputStream fin = new FileInputStream(args[0]);
    DigestInputStream din = new DigestInputStream(fin, m);
    while (din.read() != -1)
        ;//from  w  w w. ja  v  a  2 s .co m

    byte s[] = m.digest();
    for (int i = 0; i < s.length; i++) {
        System.out.print(Integer.toHexString((0x000000ff & s[i]) | 0xffffff00).substring(6));
    }
}

From source file:Main.java

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

    byte[] buf = new byte[5];

    char c;//from  ww  w  .j av  a 2  s.c  o  m

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

    int i = lnis.read(buf, 2, 3);
    System.out.println("The number of char read: " + i);

    for (byte b : buf) {
        if (b == 0)
            c = '-';
        else
            c = (char) b;

        System.out.print(c);
    }

}

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(dynamicFont.getName());
    testLabel.setFont(dynamicFont32Pt);/*w  w  w . ja v a 2 s  . com*/
    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[] args) throws Exception {
    ObjectInputStream inputStream = new ObjectInputStream(new FileInputStream("yourFile.dat"));

    Object obj = null;//from   ww  w  .jav a  2 s  . c om

    while ((obj = inputStream.readObject()) != null) {
        if (obj instanceof Person) {
            System.out.println(((Person) obj).toString());
        }
    }
    inputStream.close();
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    String fromFileName = args[0];
    String toFileName = args[1];//from w w w. j a  v  a 2 s .  c  o  m
    FileChannel in = new FileInputStream(fromFileName).getChannel();
    FileChannel out = new FileOutputStream(toFileName).getChannel();
    in.transferTo(0, (int) in.size(), out);
    in.close();
    out.close();
}

From source file:Main.java

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

    InputStream in = new FileInputStream("test.txt");
    OutputStream out = System.out;

    PrintableOutputStream pout = new PrintableOutputStream(out);
    for (int c = in.read(); c != -1; c = in.read()) {
        pout.write(c);//from w ww . j a v  a  2 s .c o m
    }
    out.close();
}