Core java
13 FebruaryHow to read excel files in java using Apache POI
In this post, we will see how to read excel in java using Apache POI example. About Apache POI project : The Apache POI Project’s mission is to create and maintain Java APIs for manipulating various file formats based upon the Office Open XML standards (OOXML) and Microsoft’s OLE 2 Compound Document format (OLE2). In […]
13 FebruaryHow to detect OS in java
In this post, we will see how to detect OS which you are using. You can use System.getProperty(“os.name”) to get current OS name. Sometimes , we need to write logic based on OS, so we get use this logic to detect current OS. Java Program: package org.arpit.java2blog; /* * @Author Arpit Mandliya */ public class […]
13 FebruaryHow to get home directory in java
In this post, we will see how to get user profile’s home directory in java. It is quite simple, we can use System.getProperty(“user.home”) to get it. Java program: package org.arpit.java2blog; /* * @Author Arpit Mandliya */ public class getHomeDirectoryMain { public static void main(String[] args) { System.out.println("--------------"); String homeDirectory=""; homeDirectory = System.getProperty("user.home"); System.out.println("Home directory is […]
12 FebruaryHow to move file to another directory in java
In this post, we will see how to move file to another directory in java. We will use java.io.File ‘s rename(File dest) to do it. In below example, we will move config_new.properties from /Users/Arpit/Desktop/Folder1 to /Users/Arpit/Desktop/Folder2 . Java Program: package org.arpit.java2blog; import java.io.File; /* * @Author : Arpit Mandliya */ public class MoveFileMain { public […]
12 FebruaryHow to rename a file in java
In this post, we will see how to rename a file in java. We can use java.io.File ‘s rename(File dest) method to rename a file. rename method returns true if operation is success else returns false. It can use this method to move a file also. You should always check if rename operation is successful […]
06 FebruaryFind start node of loop in linkedlist in java
If you want to practice data structure and algorithm programs, you can go through data structure and algorithm interview questions. In this post, we will see how to find start node of loop in linkedlist in java. We have already seen how to detect a loop in linkedlist in java. This is extension of that post. […]
06 FebruaryHow to make a file read only in java
In this post, we will see how to make a read only file in java. It is very simple. You need to just call java.io.File ‘s setReadOnly() method. 1) How to make a file read only Java program: package org.arpit.java2blog; import java.io.File; public class FileHiddenMain { public static void main(String[] args) { System.out.println("-----------------"); // Read […]
04 FebruaryRead 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. // Getting ClassLoader obj ClassLoader classLoader = this.getClass().getClassLoader(); // Getting resource(File) from […]
03 FebruaryHow 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 […]