Categories

Category Specific RSS

Append a string to a file in Java

try { BufferedWriter out = new BufferedWriter(new FileWriter(“filename”, true)); out.write(“aString”); out.close(); } catch (IOException e) { }

FacebookTwitterGoogle+PinterestTumblrStumbleUponRedditLinkedInBaiduApp.netBufferDeliciousDiggDiigoWordPressBlogger PostEmailPrintFriendlyShare

Unzipping zip file in Java

import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStream;import java.util.Enumeration;import java.util.zip.ZipEntry;import java.util.zip.ZipFile;

public class Main {

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(); […]

FacebookTwitterGoogle+PinterestTumblrStumbleUponRedditLinkedInBaiduApp.netBufferDeliciousDiggDiigoWordPressBlogger PostEmailPrintFriendlyShare

Check a file exists in Java

import java.io.*;

public class FileTest { public static void main(String args[]) { File f = new File(args[0]); System.out.println (f + (f.exists()? ” is found ” : ” is missing “)); }}

FacebookTwitterGoogle+PinterestTumblrStumbleUponRedditLinkedInBaiduApp.netBufferDeliciousDiggDiigoWordPressBlogger PostEmailPrintFriendlyShare

Create a ZIP file

/*** a simple ZIP tool**** ex. java Zip file.1 file.2 > file.zip***/import java.io.*;import java.util.zip.*;

class Zip { public static void main(String args[]) throws IOException { byte b[] = new byte[512]; ZipOutputStream zout = new ZipOutputStream(System.out); for(int i = 0; i < args.length; i ++) { InputStream in = new FileInputStream(args[i]); ZipEntry e = new ZipEntry(args[i].replace(File.separatorChar,’/’)); […]

FacebookTwitterGoogle+PinterestTumblrStumbleUponRedditLinkedInBaiduApp.netBufferDeliciousDiggDiigoWordPressBlogger PostEmailPrintFriendlyShare

hello world in java

the very first program

hello world in java

public class HelloWorld { public static void main(String[]args) { System.out.println("Hello World!"); } }

FacebookTwitterGoogle+PinterestTumblrStumbleUponRedditLinkedInBaiduApp.netBufferDeliciousDiggDiigoWordPressBlogger PostEmailPrintFriendlyShare