4 ways to read String from File in Java - Example

Just like there are many ways for writing String to text file, there are multiple ways to read String form File in Java. You can use FileReader, BufferedReader, Scanner, and FileInputStream to read text from file. One thing to keep in mind is character encoding. You must use correct character encoding to read text file in Java, failing to do so will result in logically incorrect value, where you don't see any exception but content you have read is completely different than file's original content. Many of the method which is used to read String by default uses platform's default character encoding but they do have overloaded version which accepts character encoding. 

How to download a file using HTTP in Java? Example

Hello guys, if you are looking for tutorial to understand about how to download a  file using http in Java to have deep knowledge of java basics then you will definitely learn from this article. uploading and downloading files are common task but many Java developer are not aware about how to complete that. They don't know about HTTP and how to send and receive data using HTTP. Many of them also doesn't know about HttpClient which was added in JDK 11 as well as third party libraries like Apache HttpClient which you can use before JDK 11. Anyway, don't worry, we are again here with new article that is on download file using http will give all basics about the topic to our viewers or readers.  Let's start with an example first.

How to read CSV file in Java without using a third-party library? FileReader Example Tutorial

Hello guys, as you learn Java, one thing that comes up early and often is reading from/ writing to files, and doing something useful with that data. This is also one thing which you will keep doing and also forgetting very soon, if you are not then you have good memory as I always forget it and then I do google search to find my own articles. If you read this blog then you know that in the past, I have shared how to load CSV file using OpenCSV library as well how to load a CSV file with header using Jackson but a lot of you asked me how to do this without using any third party library like Jackson or OpenCSV. So, I thought to write about this article and I actually written but forgot to publish it for a long time. But I today I found it and publishing it now, it still works well. 

How to write to a File with try-with-resource in Java? Example Tutorial

Hello Java programmers and all people learning Java, if you are familiar with try-wit-resource statement then you know that its a great language functionality and tool to open files, sockets, streams, and network connections or any resource which are require closing. Before try-with-resource was introduce in Java 7, Java developers have to manually write try catch finally block to close the connections for both success and failure cases to prevent resource leak but it was also tricky and many programmer make mistakes which actually resulted in resource leaks. One common example of that is running out of file descriptors which is used for both opening file and socket in Java.  

How to recursive copy directory in Java with sub-directories and files? Example

Hello guys, it's a common requirement in Java to copy a whole directory with sub-directories and files but it's not that straightforward, especially not until Java 7. JDK 7 introduced some new file utility methods as part of Java NIO 2 which we will use in this article to show you how to recursively copy a whole directory with sub-directories and files in Java. I'll also show you how you can use Apache Commons if you are not running on Java 7 or higher versions. Basically, You can copy a file or directory by using the copy(Path, Path, CopyOption...) method. The copy fails if the target file exists unless the REPLACE_EXISTING option is specified.

How to check if a File exists in Java with Example

Hello guys,  if you are working in Java for a couple of years, then you have come across a scenario where you need to check if a file exists or not. This is often required while writing defensive code that writes or reads from a file. While there is a method to check if a file exists in Java or not, it's not straightforward to use because it returns true if a given path represents a file or a directory. Yes, I am talking about the File. Exists () method of the java.io package. This method is the key method to solve this problem, but you need to keep in mind that it returns true if a given path exists and it's either file or directory. 

How to append text to file in Java? Example Tutorial

Hello guys, In this article, I'll teach you how to append text to a file in Java. Earlier, I have taught you guys how to create a file and write text into it, but, append is totally different than creating a new file and writing data into it. In the case of append, the file already exists and you just add text at the end of the file. One popular example of appending text into a file is a log file that is constantly updated because your application continuously appends log details into it. While you don't need to create a logging framework here, just knowing how to append text into an existing file in Java is useful for Java programmers of all kinds of experience.

How to work with Files and Directories in Java? Example Tutorial

The File API is one of the important parts of any programming language or API and even though Java's file API both new and old, is powerful, they are not intuitive enough compared to other languages like Python. Apart from knowing the essential classes and abstractions e.g. File, InputStream, OutputStream, Reader, Writer, Channel, etc, you also need to know and remember some nitty-gritty detail to avoid subtle issues. There are many articles out there on the internet which can teach you how to read and write data from the file but there are very few which will tell you to do it in the right way.

Top 5 Courses For LSAT (Law) Test in 2025 - Best of Lot

Hello guys, if you want to learn about LSAT exam and looking for best online courses to prepare for LSAT then you have come to the right place. In this article, I am going to share best LSAT online courses. But, before we get to the 5 best courses that will teach you everything you need to know about the LSAT exam, let me tell you a little bit more bout what it really is. 

The LSAT, also known as the Law School Admission Test, is basically an entrance exam that is required to get admission into most law schools. It is made up of a number of multiple-choice questions and is regularly conducted by the Law School Admission Council. 

6 Best Websites to learn Web Development in 2025

Hello guys, if you want to learn about web development and looking for best web development online  then you have come to the right place. In this article, I am going to share best web development online courses. But, before learning about the best websites and courses to start web-development, its imperative to know and understand what web-development is. Web-development is usually defined as developing a website to be published on internet(world wide web or www) or intranet(private network). 

Where to Start Learning to Code in 2025? Resources

Hello guys, if you want to coding and looking for best online courses to learn to code then you have come to the right place. In this article, I am going to share best coding and programming online courses. Coding, computers, programming, and IT has been a buzzword all through the world for last 10-15 years. In the same durations, we have seen several tech companies touch a milestone of a couple of trillion dollars in market cap. Everyday, in different parts of the world, we see new companies and organizations growing at unprecedented pace. 

How to escape HTML Special characters in JSP and Java? Example

Escaping HTML special characters in JSP or Java is a common task for Java programmers. There are many ways to escape HTML metacharacters in Java, some of which we have already seen in the last article escaping XML metacharacters in Java.  For those who are not familiar with HTML special characters, there are five e.g. <, >, &, ' and '' and if you want to print them literally just like here, Than you need to escape those characters so < becomes &lt;, > becomes &gt; and so on. 

How to lock a File before writing in Java? Example

A file is one of the oldest ways to store data and share data but if you are working in a shared file i.e a file that can be read or write by multiple readers and writers, you need to make sure that the file is locked before you try to write on it. This is needed to ensure that someone doesn't overwrite the data you are writing. Fortunately, Java provides a mechanism to lock a file before writing using the FileLock interface. You can get the handle of FileLock by using FileChannel for writing to a file. The FileChannel class is generally used to write faster in a large file and one of the common ways to write binary data in Java.

Top 20 Ethical Hacking Interview Questions and Answers for 1 to 3 years Experienced

Hello guys, if you are preparing for Ethical hacker job interview or want to become a Cyber Security expert and looking for common Ethical hacking interview questions then you have come to the right place. Earlier, I have shared Cyber Security Interview Questions and in this article, I am going to share popular Ethical Hacking Interview Questions with answers. If you have worked in the field of Ethical Hacking and Cyber Security then most likely you can answer all of these questions but if you struggle to answer any of these questions then you can always go back and join any of these best Ethical Hacking online courses to learn and revise key concepts, tooling, and techniques. 

10 Git Commands Every Programmer Should Learn

Hello guys, Git is one of the most important skill for programmers, developers and data scientist and if you don't know git then you will struggle working in a team. If you want to learn Git in 2024 then you can start with these essential Git commands. I have explained the command and give you example. For examples, I have asked ChatGPT to see how it explains and I was amazed to see the response so I have included here for my own reference. I don't if ChatGPT will remain free forever but I am taking screenshot for the questions which I am asking so that I can keep a record for myself and you in future as ChatGPT is the best instructor I have got today and its helping me to learn and revise several key concepts. 

Difference between Static and Dynamic binding in Java

Hello guys, if you are wondering what is difference between static and dynamic binding and how it affect your program execution in Java then you are at right place. When you call a method in Java, it is resolved either at compile time or at runtime, depending upon whether it's a virtual method or a static method. When a method call is resolved at compile time, it is known as static binding, while if method invocation is resolved at runtime, it is known as Dynamic binding or Late binding. Since Java is an object-oriented programming language and by virtue of that it supports Polymorphism. Because of polymorphism, a reference variable of type Parent can hold an object of type Child, which extends Parent.

Top 15 Machine Learning Interview Questions with Answers for 1 to 2 years Experienced

Hello guys, if you are preparing for Machine Learning interviews and looking for frequently asked Machine Learning interview questions then you have come to the right place. Earlier, I have shared the Data Science Interview Questions, best Machine learning courses, and  essential ML algorithms and In this article, I am going to share common Machine Learning questions from interviews. To be honest, Machine Learning interview is not easy to crack, there can be different types of questions on Machine Learning interviews from key machine learning concepts like training the model to ask different types of machine learning algorithms. 

Java ArrayList Tutorials and Examples for Beginners (with Java ArrayList Cheat Sheet)

Hello guys, if you want to learn ArrayList in-depth and looking for a complete guide on ArrayList then you have come to the right place. Earlier, I have shared the best Java collection courses and in this article, I am going to share tutorials and examples to learn and master ArrayList in Java. In the last 10 years, I have written several ArrayList tutorials, touching different ArrayList concepts and many how-to-do examples with ArrayList. In this tutorial, I am giving a summary of each of them. Why? So that any Java beginner who wants to learn ArrayList in detail, can go through the relevant tutorial and learn.

How to calculate sum and difference of two complex numbers in Java? Example

From the last couple of articles, I am writing about coding exercises for beginners e.g. yesterday you learned how to write a program from matrix multiplication in Java (see here) and a couple of days back, you have learned the recursive binary search algorithm. To continue that tradition today I am going to show you how to write a program for calculating the sum and difference of two complex numbers in Java. If you remember the complex number from you Maths classes, it has two-part real and imaginary and to add a complex number we add their real and imaginary part separately, similar to subtract complex number we minus their real and imaginary part separately. 

7 Projects You Can Do to Become a Frontend Master

Learning to code can be challenging, especially if you don't know where to begin. The greatest approach to improve your programming abilities is to use them to create coding projects.

Here are some programming projects to boost your confidence and make you a better developer.




Calculator app Abacus
The program that we all use on a daily basis is the calculator. The calculator is a project that is both simple and practical. Creating a calculator app can help you learn, how to build reusable components, how to use props, and how to handle states.


Blog Website Writing hand
Building your own blog doesn't only improve your coding skill, but your online presence too. If you have a blog and share content regularly, you can get a lot of visitors which can increase your online presence.


Weather App
Having a fully-featured weather app in your portfolio can help you a lot to get clients. And if you deploy this app, not only you but many people may get benefit from it


Spotify 2.0 Multiple musical notes
You can create Spotify 2.0, your own Spotify version. You can add as many features as you can and after completing, you can deploy it online :)

Movies App Film projector
You can create a movies app from scratch where you need to show movie details, posters, trailers, and cast. I believe that you will enjoy building this project.


YouTube UI Clone DVD
If you want to learn about grids, flexbox, and handling states then it would be better if you clone the YouTube UI. You don't need to 100% do the same as YouTube, you have the freedom to redesign and create your own version of YouTube.


Chat App Speech balloon
If you want to learn about Firebase, Firestore, Real-time database and etc. This project is for you, having this project in your portfolio can make your portfolio strong.