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) {
    File file = new File(args[0]);
    if (!file.exists()) {
        System.out.println(args[0] + " does not exist.");
        return;/* www .  jav  a2s.co  m*/
    }
    if (!(file.isFile() && file.canRead())) {
        System.out.println(file.getName() + " cannot be read from.");
        return;
    }
    try {
        FileInputStream fis = new FileInputStream(file);
        char current;
        while (fis.available() > 0) {
            current = (char) fis.read();
            System.out.print(current);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    XMLInputFactory inputFactory = XMLInputFactory.newInstance();
    XMLStreamReader reader = inputFactory.createXMLStreamReader(new FileInputStream(new File("l.xml")));
    reader = inputFactory.createFilteredReader(reader, new ElementOnlyFilter());
    System.out.println(reader.getEventType());
}

From source file:Main.java

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

    String inName = "abc.pack.gz";
    String outName = "abc";

    Pack200.Unpacker unpacker = Pack200.newUnpacker();
    JarOutputStream out = new JarOutputStream(new FileOutputStream(outName));
    InputStream in = new FileInputStream(inName);
    if (inName.endsWith(".gz")) {
        in = new GZIPInputStream(in);
    }/* w  w  w  .  j ava  2s.c  o m*/

    unpacker.unpack(in, out);
    out.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  w w.j a  v  a  2  s.  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();
}

From source file:ProgressInputSample.java

public static void main(String args[]) {
    int returnValue = NORMAL;
    try {//from   w ww. j a  va  2  s.  c om
        FileInputStream fis = new FileInputStream("person.xml");
        JLabel filenameLabel = new JLabel("persion.xml", JLabel.RIGHT);
        Object message[] = { "Reading:", filenameLabel };
        ProgressMonitorInputStream pmis = new ProgressMonitorInputStream(null, message, fis);
        InputStreamReader isr = new InputStreamReader(pmis);
        BufferedReader br = new BufferedReader(isr);
        String line;
        while ((line = br.readLine()) != null) {
            System.out.println(line);
        }
        br.close();
    } catch (Exception exception) {
        returnValue = PROBLEM;
    }
    System.exit(returnValue);
}

From source file:DataIODemo.java

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

    FileOutputStream fout = new FileOutputStream("Test.dat");
    DataOutputStream out = new DataOutputStream(fout);

    out.writeDouble(98.6);//from w ww. ja v a 2  s .c  om
    out.writeInt(1000);
    out.writeBoolean(true);

    out.close();

    FileInputStream fin = new FileInputStream("Test.dat");
    DataInputStream in = new DataInputStream(fin);

    double d = in.readDouble();
    int i = in.readInt();
    boolean b = in.readBoolean();

    System.out.println("Here are the values:  " + d + " " + i + " " + b);

    in.close();
}

From source file:ReadBinaryFile.java

public static void main(String[] args) throws Exception {
    NumberFormat cf = NumberFormat.getCurrencyInstance();

    File file = new File("product.dat");
    DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(file)));

    boolean eof = false;
    while (!eof) {
        Product movie = readMovie(in);//  w ww. j  a  v a 2s  .c o  m
        if (movie == null)
            eof = true;
        else {
            String msg = Integer.toString(movie.year);
            msg += ": " + movie.title;
            msg += " (" + cf.format(movie.price) + ")";
            System.out.println(msg);
        }
    }
    in.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    XMLInputFactory xif = XMLInputFactory.newFactory();

    FileInputStream xml = new FileInputStream("input.xml");
    XMLStreamReader xsr = xif.createXMLStreamReader(xml);
    xsr.nextTag(); // Advance to "Persons" tag
    xsr.nextTag(); // Advance to "Person" tag

    JAXBContext jc = JAXBContext.newInstance(Person.class);
    Unmarshaller unmarshaller = jc.createUnmarshaller();
    List<Person> persons = new ArrayList<Person>();
    while (xsr.hasNext() && xsr.isStartElement()) {
        Person person = (Person) unmarshaller.unmarshal(xsr);
        persons.add(person);/*ww  w .  j  a v  a  2 s . co m*/
        xsr.nextTag();
    }

    for (Person person : persons) {
        System.out.println(person.getName());
    }
}

From source file:Main.java

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

    String s = "Hello from java2s.com!!";

    FileOutputStream fos = new FileOutputStream("c:\\test.txt");

    DataOutputStream dos = new DataOutputStream(fos);

    dos.writeChars(s);// www.j av a  2  s .  co m

    dos.flush();

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

    DataInputStream dis = new DataInputStream(is);

    while (dis.available() > 0) {
        char c = dis.readChar();
        System.out.print(c);
    }

}

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);//w w w . j a  v  a 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();
}