How To Split And Merge Files Using Java

java-thumbnail

When transferring files through network or uploading to internet, it is common that file size could be the real factor. In those scenarios, splitting the file will solve your problem. The files will be splitted into small parts of chunks, that will be merged into a single file at the destination. This example shows how […]

Load Files From ClassPath Using getResourceStream()

java-thumbnail

If you are looking to load a file from the classpath of your project, the use the method getResourceAsStream(). The main difference from the File class is that, File class uses the absolute path for finding the files. java.io are dependent on the current working directory of your application. There are not dependent on the […]

Downcasting In Java

java-thumbnail

Upcasting is assigning the sub class reference object to the parent class which is allowed in Java. Downcasting is assigning parent class reference object to the sub class which is not allowed in Java. However, if you do downcasting, there will not be any compiler error. But, there will be runtime exception java.lang.ClassCastException. Then why […]

Static Nested Class In Java

java-thumbnail

Static Nested classes are inner classes which are declared inside another class and also declared with static keyword. The main difference between inner class and static nested classes is that inner classes are non-static and static nested classes are static. Also known as static classes. Static nested classes can be accessed using the enclosing class […]

Java InputStreamReader Example

java-thumbnail

InputStreamReader is bridge between bytes and streams. This usually reads the bytes from the source files and convert them to the characters with the specified charset. Which charset has to be used will be specified with the name. In this example I have used “UTF-8″ charset. This exampls shows how to use InputStreamReader for reading […]

How To Count Files In A Directory Using Java

java-thumbnail

This example shows how to count the number of files in a folder. File class defines a method list() which returns the array of file names in the directory. By getting the length of that array would mean the number of files in the folder. Lets look at the simple example. CountFilesExample.java

How To Check Type Of Drive (Hard Disk / Removable Disk) In Java

java-thumbnail

This example shows how to check if for a hard disk or removable disk in the system. FileSystemView.isFloppyDrive() returns if the disk is removable. If you look at this example, it prints some of the details about the drive like read, write, etc. DrivesExample.java Output…

How To Get Operating System Drive Letters in Java

java-thumbnail

This example shows how to list the system drive letters using Java program. File.listRoots() method returns the drive letter from the file system. Lets look at the simple example for listing the operating system’s drive letters for windows. ListOSDrivesExample.java Output…

How To Open Word Document In Java

java-thumbnail

This example shows how to open a word document using Java. If you are working with tools where you have to open the document by clicking on it, you can use the java.awt.Desktop API to easily open the document by passing the file object. Note that this API will open any document passed into the […]

Static Initializer , Instance Initializer And Constructor In Java

java-thumbnail

This example show the order of the Java initialization blocks. Java has static initializer, instance initializer and constructor for initializing the variables. These blocks are used for the different purposes and leads to confusion among the programmers. Order of the execution of these blocks are as follows: All Static Initializers executed in the same order […]