• 13 February

    How 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: [crayon-662c82b385799132061304/] When I ran above program, I got below output: [crayon-662c82b3857a1051513181/]

  • 12 February

    How 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: [crayon-662c82b385a76813400509/] When I ran above program, I got following output: [crayon-662c82b385a7d464823037/]

  • 12 February

    How 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 February

    Find 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 February

    How 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: [crayon-662c82b387077119444748/] When you run above program, you will get following output: [crayon-662c82b38707f037627473/] 2) How to make it […]

  • 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-662c82b3871be879188751/] Project structure: Java Program: [crayon-662c82b3871c2964859819/] 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: […]