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

License:asdf

public static void main(String[] args) throws ClassNotFoundException, IOException {
    FileOutputStream fos = new FileOutputStream("objects.tmp");

    ObjectOutputStream oos = new ObjectOutputStream(fos);
    oos.writeObject("asdf");
    oos.flush();/*from   ww w .j  a  v  a2  s.c  o  m*/
    fos.close();

    FileInputStream fis = new FileInputStream("objects.tmp");
    ObjectInputStream ois = new ObjectInputStream(fis);
    String t = (String) ois.readObject();
    fis.close();

}

From source file:Bzip2Compress.java

public static void main(final String[] args) throws Exception {
    if (2 != args.length) {
        System.out.println("java Bzip2Compress <input> <output>");
        System.exit(1);/* w w  w  .  j  av  a  2s. c o  m*/
    }

    final File source = new File(args[0]);
    final File destination = new File(args[1]);
    final BZip2CompressorOutputStream output = new BZip2CompressorOutputStream(
            new FileOutputStream(destination));
    final FileInputStream input = new FileInputStream(source);
    copy(input, output);
    input.close();
    output.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Class.forName("oracle.jdbc.driver.OracleDriver");
    Connection conn = DriverManager.getConnection(url, username, password);
    conn.setAutoCommit(false);/*from  ww w .j a va 2s .c  om*/

    String sql = "INSERT INTO pictures (name, description, image) VALUES (?, ?, ?)";
    PreparedStatement stmt = conn.prepareStatement(sql);
    stmt.setString(1, "java.gif");
    stmt.setString(2, "Java Official Logo");

    File image = new File("D:\\a.gif");
    FileInputStream fis = new FileInputStream(image);
    stmt.setBinaryStream(3, fis, (int) image.length());
    stmt.execute();

    conn.commit();
    fis.close();
    conn.close();
}

From source file:PrintImage.java

static public void main(String args[]) throws Exception {
    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];/* ww  w .j av  a 2 s  . c o m*/
    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();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    int sChunk = 8192;

    String zipname = "a.gz";
    FileOutputStream out = new FileOutputStream(zipname);
    GZIPOutputStream zipout = new GZIPOutputStream(out);
    byte[] buffer = new byte[sChunk];

    FileInputStream in = new FileInputStream(args[0]);
    int length;//from  ww  w . j av  a 2 s  .c o m
    while ((length = in.read(buffer, 0, sChunk)) != -1)
        zipout.write(buffer, 0, length);
    in.close();
    zipout.close();

}

From source file:Main.java

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

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

    int i = fis.read();

    char c = (char) i;

    System.out.println(c);//from  www  .jav  a 2 s. c  o m

    // close file input stream
    fis.close();

}

From source file:FileInputStreamDemo.java

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

    // Read and display data
    int i;/* w  w  w.j  a  v  a2  s .  c om*/
    while ((i = fis.read()) != -1) {
        System.out.println(i);
    }

    fis.close();

}

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 2s  .  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();
}

From source file:Main.java

static public void main(String args[]) throws Exception {
    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];/*from w  ww .j  a va  2  s  .c o  m*/
    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();
}

From source file:config.MainClass.java

/**
 * @param args the command line arguments
 *//*from w  ww .j av  a 2s  . co  m*/
public static void main(String[] args) {
    // TODO code application logic here
    File file = new File("D:\\iti images\\Dish Party_6-11-2014\\IMG_5376.jpg");
    byte[] bFile = new byte[(int) file.length()];

    try {
        FileInputStream fileInputStream = new FileInputStream(file);
        //convert file into array of bytes
        fileInputStream.read(bFile);
        fileInputStream.close();
    } catch (Exception e) {
        System.out.println("Error in reading the image");
    }
    UserData data = new UserData();
    data.setUserName("hasby allah");
    data.setBirthday(new Date());
    data.setPhone("65656");
    data.setFullName("7asby allah w n3m el wakel");
    data.setAddress("haram");
    data.setPassword("password");
    data.setImage(bFile);
    AbstractApplicationContext fact = new ClassPathXmlApplicationContext("SpringConfig.xml");
    DaoService serviceInterface = fact.getBean(DaoService.class);
    serviceInterface.save(data);
}