Core java
- 04 February
Read a file from resources folder in java
In this post, we will see how to read a file from resources folder in java. If you create a maven project(simple java or dynamic web project) , you will see folder src/java/resources. You can read from resources folder using these simple code. [crayon-674438a1a3033591174064/] Project structure: Java Program: [crayon-674438a1a303a534202756/] When you run above program, you […]
- 03 February
How to read properties file in java
In this post , we will see how to read properties file in java. Properties files are used in java projects to externalise configuration, for example, database settings. Java uses Properties class to store the above key-values pair. Properties.load() method is very convenient to load properties file in form of key-values pairs. Properties file looks […]
- 01 February
How to read object from a file in java
In this post, we will see how to read object from file in java. In last post, we have already seen how to write object to a file and created employee.ser , now in this post, we are going to read same file and retrieve back Employee object. Java Serialization Tutorial: Serialization in javaJava Serialization […]
- 01 February
How to write object to a file in java
If you want to send object over network, then you need to  write object to a file and convert it to the stream. This process can be referred as serialization. Object needs to implement Serializable interface which is marker interface  interface and we will use java.io.ObjectOutputStream to write object to a file. Java Serialization Tutorial: […]
- 01 February
How to get last modified date of file in java
In this post, we will see how to get last modified date of file in java. We can use java.io.File’s lastModified() method to get last modified date. This function returns time in milliseconds(long). We can convert this to required date format using SimpleDateFormat. Java Program: [crayon-674438a1a371b003602400/] When you run above program, you will get below output: […]
- 30 January
How to get all files with certain extension in a folder in java
In this post, we will see how to list all files with certain extension in a folder. For example, you want to list all .jpg or .zip files in a folder. We will  use FilenameFilter interface to list the files in a folder, so we will create a inner class which will implement FilenameFilter interface and implement […]
- 30 January
How to delete non empty directory in java
In this post, we will see how to delete Directory/Folder which is non empty. You can use java.io.File ‘s delete empy folder but you can not delete it if it is non empty. There are multiple ways to do it. Using java recursion Using Apache common IO Using java recursion: It is very straight forward to […]
- 30 January
How to download file from URL in java
In this post, we will see how to download file from URL in java. It can be used when you want to automatically download any file from URL using java. There are many ways to do it and some of them are : Using Java input output stream Using apache common IO Using NIO Java […]
- 30 January
How to check if a file exists in Java
It is very easy to check if file exists or not in your file system. You can use java.io.File’s exists() method to check if file exists or not. Java program : [crayon-674438a1a3c75533163312/] When you run above program, you will get following output: [crayon-674438a1a3c78864950233/]