How to recursively delete file in directory?
This snippet show how to recursively delete directories. This is a classic example of use of recursion to figure out files in sub folders and so on..<!--break-->package...
View ArticleHow to Read Lines from File As String Array?
This snippet shows how read all the lines of a file into an array and finally print the lines. It uses the FileReader to open the file, then reads the each of the lines using the readLine() method and...
View ArticleSimple JDBC Dao for Oracle
This snippet shows how to connect to an Oracle database using JDBC. Open the connection, execute the query, get result set and close the connection.<!--break-->package...
View ArticleHowto programatically move mouse?
This snippet shows how to move or re-position the mouse on the screen. This involves the use of Robot API avaiable as part of java.awt package. Basically using the robot.mouseMove(x, y) method the...
View ArticleSound Player for .WAV and .AU Files
This snippet shows how to play .wav or .au file. The following steps need to be done.- Get the AudioInputStream for the audio file- Check the PCM_SIGNED encoding, else convert- Create the AudioClip...
View ArticleMIDI Sound Player
This snippet shows how to play music Midi files (musical sequences).In order to play midi sequences, the Midi Sequencer is needed which is retrieved by MidiSystem.getSequencer() method. Then midi...
View ArticleHow to generate beep in Java?
This simple snippet shows how to produce the Beep Sound in Java using the AWT Toolkit.The key thing here is is the delay introduced in the subsequent beeps. Changing the delay between beeps, you can...
View ArticleDisplay background Image in Applet
Displaying backgound Image in an Applet is a two step process.First - Get the handle to the image using a simplified method getImage() or using the MediaTracker API. This is done in the Applet's init()...
View ArticleHow to playing an audio file in Applet?
This snippet shows how to play an Audio Clip (midi, wav etc.) from an Applet.The Audio Clip is loaded from the Applet CodeBase. The clip is loaded in Applet's init() method, then its started in the...
View ArticleRuntime Jar File Loader
Normally all the classes we need to run a java program are packaged in the jar files.These jars are added to the classpath by the JVM which loaded them as required. What if we want these jars to be...
View ArticleHow to execute Shell Command?
This snippets demonstrates how to execute shell command (navtive to OS) and captures its output as if it was running from the command line. Once the command is executed, it waits for it, and captures...
View ArticleLoad Properties from Classpath
Loading properties is easy as long as you know the path to the properties file. This can be issue at times when you either don't know the exact location of the file or it can change based on...
View ArticleGet StackTrace as String
Its easy to print the stack trace using e.printStackTrace() where e is instance of an Exception/Throwable. This prints the trace to the Standard Error stream. But how about if you want to have the...
View ArticleHow to create nonexistent directories recursively ?
The following snippet checks if a given directory exists or not. If it does not it, then creates it. It also creates any non existent directories in the path. The magic is performed by the java.io.File...
View ArticleHow to change Java Application Look and Feel?
Java Swing API renders the GUI in the Java Look and Feel but at times we want it use a certain look and feel like Motif or Windows or want to change look and feel dynamically from the application...
View ArticleMD5 Generator
At times we need to create a one way hash(digest) for a give string/text, there are various algorithm that can be used to do so (MD5,SHA etc.)The snippet below shows how this can be...
View ArticleCapture Screen shot as Image
Have you wondered how tools like Snagit capture the display screen and create an image file. Doing that using java AWT is very easy. Just few lines of code. Also you can save the image as JPG, GIF, PNG...
View ArticleRecursively Convert GIF Images to JPEG
This snippets shows how to re-cursively convert image in gif format to jpeg.<!--break-->package com.livrona.image.tools;import java.awt.image.BufferedImage;import java.io.File;import...
View ArticleHow to Capture Screen Shot?
Have you wondered how tools like Snagit capture the display screen and create an image file. Doing that using java AWT is very easy. Just few lines of code. Also you can save the image as JPG, GIF, PNG...
View ArticleThread Dump in JSP
<%@ page language="java" import="java.util.*,java.lang.Thread.State" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%><html><head><meta...
View Article