List of usage examples for java.io FileOutputStream close
public void close() throws IOException
From source file:MainClass.java
public static void main(String[] args) { Employee e = new Employee(); e.name = "Jor Lee"; e.address = "USA"; e.SSN = 11122333;//from w w w . java 2 s. c om e.number = 101; try { FileOutputStream fileOut = new FileOutputStream("employee.ser"); ObjectOutputStream out = new ObjectOutputStream(fileOut); out.writeObject(e); out.close(); fileOut.close(); } catch (IOException i) { i.printStackTrace(); } }
From source file:MainClass.java
public static void main(String[] args) throws IOException { for (int i = 0; i < args.length; i++) { FileInputStream fin = new FileInputStream(args[i]); ZipInputStream zin = new ZipInputStream(fin); ZipEntry ze = null;/* ww w . java 2s .co m*/ while ((ze = zin.getNextEntry()) != null) { System.out.println("Unzipping " + ze.getName()); FileOutputStream fout = new FileOutputStream(ze.getName()); for (int c = zin.read(); c != -1; c = zin.read()) { fout.write(c); } zin.closeEntry(); fout.close(); } zin.close(); } }
From source file:Employee.java
public static void main(String[] args) { Employee e = new Employee(); e.name = "A"; e.address = "B"; e.SSN = 11111;/*from ww w . j a v a 2 s . c om*/ e.number = 101; try { FileOutputStream fileOut = new FileOutputStream("employee.ser"); ObjectOutputStream out = new ObjectOutputStream(fileOut); out.writeObject(e); out.close(); fileOut.close(); } catch (IOException i) { i.printStackTrace(); } }
From source file:bigfat.hadoop.HDFSDirInputStream.java
/** * Test case, input int dir wants to read and the file to output * //from w w w .ja v a 2 s. c o m * @param args * @throws IOException */ public static void main(String args[]) throws IOException { Configuration conf = new Configuration(); FileSystem fs = FileSystem.get(conf); HDFSDirInputStream inp = new HDFSDirInputStream(fs, args[0]); FileOutputStream ops = new FileOutputStream(args[1]); int r; while ((r = inp.read()) != -1) { ops.write(r); } ops.close(); }
From source file:Main.java
public static void main(String[] args) { for (int i = 0; i < args.length; i++) { if (args[i].toLowerCase().endsWith(".dfl")) { try { FileInputStream fin = new FileInputStream(args[i]); InflaterInputStream iis = new InflaterInputStream(fin); FileOutputStream fout = new FileOutputStream(args[i].substring(0, args[i].length() - 4)); for (int c = iis.read(); c != -1; c = iis.read()) { fout.write(c);/*from w w w. java 2 s.co m*/ } fout.close(); } catch (IOException ex) { System.err.println(ex); } } else { System.err.println(args[i] + " does not appear to be a deflated file."); } } }
From source file:MainClass.java
public static void main(String[] args) { for (int i = 0; i < args.length; i++) { if (args[i].toLowerCase().endsWith(".gz")) { try { FileInputStream fin = new FileInputStream(args[i]); GZIPInputStream gzin = new GZIPInputStream(fin); FileOutputStream fout = new FileOutputStream(args[i].substring(0, args[i].length() - 3)); for (int c = gzin.read(); c != -1; c = gzin.read()) { fout.write(c);/*w ww . j a v a 2 s . c o m*/ } fout.close(); } catch (IOException ex) { System.err.println(ex); } } else { System.err.println(args[i] + " does not appear to be a gzipped file."); } } }
From source file:Main.java
public static void main(String[] args) throws IOException { ZipFile zf = new ZipFile("a.zip"); Enumeration e = zf.entries(); while (e.hasMoreElements()) { ZipEntry ze = (ZipEntry) e.nextElement(); FileOutputStream fout = new FileOutputStream(ze.getName()); InputStream in = zf.getInputStream(ze); for (int c = in.read(); c != -1; c = in.read()) { fout.write(c);/* ww w . j a va 2 s . c o m*/ } in.close(); fout.close(); } }
From source file:Main.java
public static void main(String[] args) { FTPClient client = new FTPClient(); FileOutputStream fos = null; client.connect("ftp.domain.com"); client.login("admin", "secret"); String filename = "sitemap.xml"; fos = new FileOutputStream(filename); client.retrieveFile("/" + filename, fos); fos.close(); client.disconnect();/*from w w w . j a va 2 s . com*/ }
From source file:com.rabbitmq.examples.FileConsumer.java
public static void main(String[] args) { Options options = new Options(); options.addOption(new Option("h", "uri", true, "AMQP URI")); options.addOption(new Option("q", "queue", true, "queue name")); options.addOption(new Option("t", "type", true, "exchange type")); options.addOption(new Option("e", "exchange", true, "exchange name")); options.addOption(new Option("k", "routing-key", true, "routing key")); options.addOption(new Option("d", "directory", true, "output directory")); CommandLineParser parser = new GnuParser(); try {/*w w w. j a v a2 s . c o m*/ CommandLine cmd = parser.parse(options, args); String uri = strArg(cmd, 'h', "amqp://localhost"); String requestedQueueName = strArg(cmd, 'q', ""); String exchangeType = strArg(cmd, 't', "direct"); String exchange = strArg(cmd, 'e', null); String routingKey = strArg(cmd, 'k', null); String outputDirName = strArg(cmd, 'd', "."); File outputDir = new File(outputDirName); if (!outputDir.exists() || !outputDir.isDirectory()) { System.err.println("Output directory must exist, and must be a directory."); System.exit(2); } ConnectionFactory connFactory = new ConnectionFactory(); connFactory.setUri(uri); Connection conn = connFactory.newConnection(); final Channel ch = conn.createChannel(); String queueName = (requestedQueueName.equals("") ? ch.queueDeclare() : ch.queueDeclare(requestedQueueName, false, false, false, null)).getQueue(); if (exchange != null || routingKey != null) { if (exchange == null) { System.err.println("Please supply exchange name to bind to (-e)"); System.exit(2); } if (routingKey == null) { System.err.println("Please supply routing key pattern to bind to (-k)"); System.exit(2); } ch.exchangeDeclare(exchange, exchangeType); ch.queueBind(queueName, exchange, routingKey); } QueueingConsumer consumer = new QueueingConsumer(ch); ch.basicConsume(queueName, consumer); while (true) { QueueingConsumer.Delivery delivery = consumer.nextDelivery(); Map<String, Object> headers = delivery.getProperties().getHeaders(); byte[] body = delivery.getBody(); Object headerFilenameO = headers.get("filename"); String headerFilename = (headerFilenameO == null) ? UUID.randomUUID().toString() : headerFilenameO.toString(); File givenName = new File(headerFilename); if (givenName.getName().equals("")) { System.out.println("Skipping file with empty name: " + givenName); } else { File f = new File(outputDir, givenName.getName()); System.out.print("Writing " + f + " ..."); FileOutputStream o = new FileOutputStream(f); o.write(body); o.close(); System.out.println(" done."); } ch.basicAck(delivery.getEnvelope().getDeliveryTag(), false); } } catch (Exception ex) { System.err.println("Main thread caught exception: " + ex); ex.printStackTrace(); System.exit(1); } }
From source file:MainClass.java
public static void main(String[] args) throws IOException { ZipFile zf = new ZipFile(args[0]); Enumeration e = zf.entries(); while (e.hasMoreElements()) { ZipEntry ze = (ZipEntry) e.nextElement(); System.out.println("Unzipping " + ze.getName()); FileOutputStream fout = new FileOutputStream(ze.getName()); InputStream in = zf.getInputStream(ze); for (int c = in.read(); c != -1; c = in.read()) { fout.write(c);/* w w w .j a va2s .c o m*/ } in.close(); fout.close(); } }