How to get JDBC Driver Property Info in Java?

Below java code shows you JDBC driver property information – /**************************************************************************************** * Created on 04-2011 Copyright(c) http://kodehelp.com All Rights Reserved. ****************************************************************************************/ package com.kodehelp.javasql; import java.sql.Driver; import java.sql.DriverManager; import java.sql.DriverPropertyInfo; import java.util.Properties; /** * Created by http://kodehelp.com * Date: 4/29/11 */ public class GetDriverPropertyInfo { public static void main(String args[]) throws Exception{ Class.forName(“oracle.jdbc.driver.OracleDriver”); Properties info = …

Read More

How To Convert String To InputStream in Java?

Below Java code show how to convert String to InputStream using ByteArrayInputStream class – /********************************************************************************** * Created on 04-2011 Copyright(c) http://kodehelp.com All Rights Reserved. **********************************************************************************/ package com.kodehelp.javaio; import java.io.ByteArrayInputStream; import java.io.InputStream; import java.io.UnsupportedEncodingException; /** * Created by http://kodehelp.com * Date: 4/28/11 */ public class StringToInputStream { public static void main(String[] args){ String text = “Converting …

Read More

How To Read Text File in Java?

Below code example shows how to read the text file in java. First the file is read into inputstream. /********************************************************************************** * Created on 04-2011 Copyright(c) http://kodehelp.com All Rights Reserved. **********************************************************************************/ package com.kodehelp.javaio; import java.io.*; /** * Created by http://kodehelp.com * Date: 4/28/11 */ public class ReadTextFile { public static void main(String[] args) throws Exception{ InputStream …

Read More

How To Convert InputStream to String in Java

Below Java code show how to read the file in InputStream and convert the inputStream to String. In this example the file used (“TEST.txt”) is kept in the root directory of your project. /********************************************************************************** * Created on 04-2011 Copyright(c) http://kodehelp.com All Rights Reserved. **********************************************************************************/ package com.kodehelp.javaio; import java.io.*; /** * Created by http://kodehelp.com * Date: …

Read More

How To Get Extension of a File in Java?

Below Java code example show how to retrieve the extension of File using Java File object – /********************************************************************************** * Created on 04-2011 Copyright(c) http://kodehelp.com All Rights Reserved. **********************************************************************************/ package com.kodehelp.javaio; import java.io.File; /** * Created by http://kodehelp.com * Date: 4/28/11 */ public class ExtensionOfFile { public static final String DOT_SEPARATOR = “.”; public static void …

Read More

Java Code Example for Applet: getDocumentBase() Method

Java Code Example for Applet: getDocumentBase() Method

getDocumentBase() emthod of Applet class returns the URL of the document in which this applet is embedded. For example, suppose an applet is contained within the document: C:/Vigilance/samples/bin/index.html Then the document base is : C:/Vigilance/samples/bin/index.html Below java code show how to get the document base in Applet : /********************************************************************************** * Created on Nov, 2004 Copyright(c) …

Read More

Java Code Example for Java Applet

An applet is a small program that is intended not to be run on its own, but rather to be embedded inside another application. The Applet class must be the superclass of any applet that is to be embedded in a Web page or viewed by the Java Applet Viewer. The Applet class provides a …

Read More

Java Code Example for BufferedReader to read Character InputStream

BufferedReader class of Java API provides a way to read the character inputstream, by buffering the characters which provides an efficient way to read the characters, arrays and lines. The buffer size may be specified, or the default size may be used. The default is large enough for most purposes. In general, each read request …

Read More

Java Code Example for BufferedOutputStream : flush() Method

flush() method of BufferedOutStream flushes this buffered output stream. This forces any buffered output bytes to be written out to the underlying output stream. Overrides: flush in class FilterOutputStream Throws: IOException – if an I/O error occurs. Below code example show how the output stream is flushed and writes out the output stream. /********************************************************************************** * …

Read More

Java Code Example for BufferedOutputStream : write(byte[]b, int off, int len) Method

BufferedOutputStream’s write(byte[]b,int off,int len) method writes len bytes from specified array of byte starting from offset off to the outputstream. This method stores bytes from the given array into this stream’s buffer, flushing the buffer to the underlying output stream as needed. If the requested length is at least as large as this stream’s buffer, …

Read More

Java Code Example for BufferedOutputStream : write(int b) Method

BufferedOutputStream’s write(int b) method overrides write(int b) method of FilterOutputStream. This method writes the specified byte to this output stream. The write method of FilterOutputStream calls the write method of its underlying output stream, that is, it performs out.write(b). Implements the abstract write method of OutputStream. Parameters: b – the byte. Throws: IOException – if …

Read More