Example usage for java.io FileInputStream close

List of usage examples for java.io FileInputStream close

Introduction

In this page you can find the example usage for java.io FileInputStream close.

Prototype

public void close() throws IOException 

Source Link

Document

Closes this file input stream and releases any system resources associated with the stream.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    FileInputStream fin = new FileInputStream("test.txt");
    int i;// ww  w. j av a 2  s  . c  om
    do {
        i = fin.read();
        if (i != -1)
            System.out.printf("%02X ", i);
    } while (i != -1);
    fin.close();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    GZIPOutputStream out = new GZIPOutputStream(new FileOutputStream("outfile.gzip"));
    FileInputStream in = new FileInputStream("infilename");

    byte[] buf = new byte[1024];
    int len;/*from   ww  w . j  a  v  a2  s .  co m*/
    while ((len = in.read(buf)) > 0) {
        out.write(buf, 0, len);
    }
    in.close();

    out.finish();
    out.close();
}

From source file:CopyBytes.java

public static void main(String[] args) throws IOException {
    File inputFile = new File("input.txt");
    File outputFile = new File("output.txt");

    FileInputStream in = new FileInputStream(inputFile);
    FileOutputStream out = new FileOutputStream(outputFile);
    int c;/*from ww  w.  jav  a  2 s.co  m*/

    while ((c = in.read()) != -1)
        out.write(c);

    in.close();
    out.close();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String outFilename = "outfile.gzip";
    GZIPOutputStream out = new GZIPOutputStream(new FileOutputStream(outFilename));

    String inFilename = "infilename";
    FileInputStream in = new FileInputStream(inFilename);

    byte[] buf = new byte[1024];
    int len;/*from  w  w  w .j a  v  a  2  s.  co  m*/
    while ((len = in.read(buf)) > 0) {
        out.write(buf, 0, len);
    }
    in.close();

    out.finish();
    out.close();
}

From source file:BufferedInputStreamDemo.java

public static void main(String args[]) throws Exception {
    FileInputStream fis = new FileInputStream(args[0]);

    BufferedInputStream bis = new BufferedInputStream(fis);

    int i;//ww w  .  ja  va  2  s. c  o m
    while ((i = bis.read()) != -1) {
        System.out.println(i);
    }

    fis.close();
}

From source file:Main.java

public static void main(String[] args) throws IOException {
    FileInputStream fin = new FileInputStream("a.zip");
    Checksum cs = new CRC32();
    for (int b = fin.read(); b != -1; b = fin.read()) {
        cs.update(b);/*w w  w .j  a v  a2  s. co m*/
    }
    System.out.println(cs.getValue());
    fin.close();
}

From source file:PrintImage.java

static public void main(String args[]) throws Exception {
    try {/*  w  ww .  j av  a 2 s . c om*/
        PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
        pras.add(new Copies(1));

        PrintService pss[] = PrintServiceLookup.lookupPrintServices(DocFlavor.INPUT_STREAM.GIF, pras);

        if (pss.length == 0)
            throw new RuntimeException("No printer services available.");

        PrintService ps = pss[0];
        System.out.println("Printing to " + ps);

        DocPrintJob job = ps.createPrintJob();

        FileInputStream fin = new FileInputStream("YOurImageFileName.PNG");
        Doc doc = new SimpleDoc(fin, DocFlavor.INPUT_STREAM.GIF, null);

        job.print(doc, pras);

        fin.close();
    } catch (IOException ie) {
        ie.printStackTrace();
    } catch (PrintException pe) {
        pe.printStackTrace();
    }
}

From source file:CachedRS.java

public static void main(String[] args) throws Exception {
    FileInputStream fis = new FileInputStream(CRS_FILE_LOC);
    ObjectInputStream in = new ObjectInputStream(fis);
    CachedRowSet crs = (CachedRowSet) in.readObject();
    fis.close();
    in.close();/*from  ww  w . ja v  a2s  .c om*/

    Class.forName("oracle.jdbc.driver.OracleDriver");
    crs.setUrl("jdbc:oracle:thin:@localhost:1521:ORCL");
    crs.setUsername("yourName");
    crs.setPassword("mypwd");
    String sql = "SELECT SSN, Name, Salary, Hiredate FROM Employees WHERE SSN=?";
    crs.setCommand(sql);
    crs.setInt(1, 111111111);
    crs.execute();

    FileOutputStream fos = new FileOutputStream(CRS_FILE_LOC);
    ObjectOutputStream out = new ObjectOutputStream(fos);
    out.writeObject(crs);
    out.close();
    crs.close();

    fis = new FileInputStream(CRS_FILE_LOC);
    in = new ObjectInputStream(fis);
    crs = (CachedRowSet) in.readObject();
    fis.close();
    in.close();

    while (crs.next()) {
        System.out.print("SSN: " + crs.getInt("ssn"));
        System.out.print(", Name: " + crs.getString("name"));
        System.out.print(", Salary: $" + crs.getDouble("salary"));
        System.out.print(", HireDate: " + crs.getDate("hiredate"));
    }
    crs.close();
}

From source file:com.datatorrent.stram.api.IotDev.java

public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {
    ClassLoader loader = IotDev.class.getClassLoader();
    LOG.debug(String.valueOf(loader.getResource("\n\nPATH : \nfoo/Test.class")));

    FileInputStream f = new FileInputStream("/home/" + name + "/fileURL");
    LinkedHashSet<URL> launchDependencies = read(f);
    loadDependencies(launchDependencies);

    LOG.debug("\n\nURLS\n\n");

    for (URL l : launchDependencies) {
        LOG.debug("\n URL " + l);
    }//from w  w  w .j  a va  2  s . com

    // FileInputStream fis = new FileInputStream("./" + LogicalPlan.SER_FILE_NAME);
    FileInputStream fis = new FileInputStream("/home/" + name + "/file");
    try {
        lp = LogicalPlan.read(fis);
    } finally {
        fis.close();
    }
    StramLocalCluster lc = new StramLocalCluster(lp);
    lc.run();
}

From source file:SerializationUtilsTrial.java

public static void main(String[] args) {
    try {//from  w  w w. java  2s .c om
        // File to serialize object to
        String fileName = "testSerialization.ser";

        // New file output stream for the file
        FileOutputStream fos = new FileOutputStream(fileName);

        // Serialize String
        SerializationUtils.serialize("SERIALIZE THIS", fos);
        fos.close();

        // Open FileInputStream to the file
        FileInputStream fis = new FileInputStream(fileName);

        // Deserialize and cast into String
        String ser = (String) SerializationUtils.deserialize(fis);
        System.out.println(ser);
        fis.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}