Good knowledge of Java IO API is important for any Java developer but many of them barely pay attention to Java IO and NIO API, and that's why they often struggle during Java interviews when a question related to Input-Outpu…
Read more
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…
Read more
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 be…
Read more
Since compressing and archiving old log files is an essential housekeeping job in any Java application environment, a Java programmer should know how to compress files in .zip format and then how to read them programmatically …
Read more
Prior to Java 7, reading a text file into an ArrayList involves a lot of boilerplate coding, as you need to read the file line by line and insert each line into an ArrayList , but from Java 7 onward, you can use the utility met…
Read more
Even though Java is considered one of the best feature-rich programming languages, until Java 7, It didn't have any method to copy a file from one directory to another directory. It did have the java.io.File class, which pr…
Read more
There was no easy way to read a text file as String in Java until JDK 7 , which released NIO 2. This API now provides a couple of utility methods that you can use to read the entire file as String e.g. Files.readAllBytes() retu…
Read more
You can load data from a CSV file in a Java program by using BufferedReader class from the java.io package. You can read the file line by line and convert each line into an object representing that data. Actually, there are …
Read more
You can use either OutputStream or Writer class in Java to write data to a file in Java. For example, you can use a combination of FileWriter and BufferedWriter to write text content into a text file in Java. If you want to wr…
Read more
In the last tutorial, you have learned how to write data to a file in Java , and in this tutorial, you will learn how to append text to a file in Java. What is the difference between simply writing to a file vs appending data t…
Read more
Even though both FileReader and FileInputStream are used to read data from a file in Java, they are quite different. The main difference between the FileReader and FileInputStream is that one reads data from a character str…
Read more
Java programming language provides streams to read data from a file, a socket and from other sources e.g. byte array, but developers often find themselves puzzled with several issues e.g. how to open connection to read data, how…
Read more
There are multiple ways to read a file in Java e.g. you can use a Scanner as we have seen in the last example , or you can use the BufferedReader class. The advantage of using a BufferedReader to read a text file is speed. It a…
Read more
Hello guys, if you are working in Java or just started with Java then you have must come across statements like System.out.println("Hello world") to print something on console or command prompt . This is actually the f…
Read more
Hello guys, I have been sharing a lot of Java interview question in this blog and so far I have shared Java interview questions on Core Java , Collections , Java 8 , Multithreading , design patterns , Garbage Collections , Sprin…
Read more
Many beginners confused with the fact that the same class java.io.File is used to create both file and directories in Java . I agree, this is not very intuitive and junior developers probably start looking for a class called …
Read more
You can read a text file in Java by using either Files , BufferedReader or Scanner class. Both classes provide convenient methods to read a text file line by line e.g. Scanner provides nextLine() method and BufferedReader pro…
Read more
Hello guys, if you are wondering how to take user input from command prompt in Java like username and password then don't worry. Java provides several utilities like Scanner and BufferedReader to read input from command prom…
Read more
One of the readers of my blog Javarevisited emailed me yesterday about how to check if a file is empty in Java and that's why I am writing this post to show that using an example. The common approach for checking if a file i…
Read more
Hello guys, welcome to my blog. Today, we'll discuss another interesting Java interview question, BufferedReader vs Scanner. It's not only important from an interview point of view but also to work efficiently with Java.…
Read more