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 …
Java File IO
Load Files From ClassPath Using getResourceStream()
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 …
Java InputStreamReader Example
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
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 Open Word Document In Java
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 …
java.io.NotSerializableException
java.io.NotSerializableException is thrown when the object is not eligible for the serialization. You must implement the Serializable interface to make the class eligible for the serialization. This is a marker interface which tells the JVM that the class can be serialized. Look at the below example. Employee.java Employee class which not implementing the serializable interface. NotSerializableExceptionExample.java …
Append To File using FileOutputStream
In my previous example I have explained about how to write to a file using the FileOutputStream. This example demonstrates how to append to an existing file without creating the new file. By default, FileOutputStream creates new file or overwrite when we try to write into a file. If you want to append with the …
Java PrintStream Example
In my previous example I have explained about the PrintWriter for printing the formatted output to the console and file. This example demonstrates how to use the PrintStream. Note that PrintWriter and PrintStream defines the similar methods and work very much similar, except that PrintWriter writes the sequence of characters and PrintStream writes the stream of …