Maruthi Krishna has Published 951 Articles

How to add/append content to an existing file using Java?

Maruthi Krishna

Maruthi Krishna

Updated on 12-Sep-2019 06:15:25

370 Views

In most scenarios, if you try to write content to a file, using the classes of the java.io package, the file will be overwritten i.e. data existing in the file is erased and the new data is added to it.But, in certain scenarios like logging exceptions into a file (without ... Read More

How to write data to .csv file in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 11-Sep-2019 14:24:40

15K+ Views

A library named OpenCSV provides API’s to read and write data from/into a.CSV file. Here it is explained how to write the contents of a .csv file using a Java program.Maven dependency    com.opencsv    opencsv    4.4    org.apache.commons    commons-lang3    3.9 The CSVWriter class of ... Read More

How to read data from .csv file in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 11-Sep-2019 14:16:41

3K+ Views

A library named OpenCSV provides API’s to read and write data from/into a.CSV file. Here it is explained how to read the contents of a .csv file using a Java program.Maven dependency    com.opencsv    opencsv    4.4    org.apache.commons    commons-lang3    3.9 The CSVReader class of ... Read More

How to create a directory in project folder using Java?

Maruthi Krishna

Maruthi Krishna

Updated on 11-Sep-2019 14:10:53

973 Views

The class named File of the java.io package represents a file or directory (path names) in the system. This class provides various methods to perform various operations on files/directories.The mkdir() method of this class creates a directory with the path represented by the current object.Therefore, to create a directory −Instantiate ... Read More

How to move files using FileUtils in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 11-Sep-2019 14:07:37

504 Views

Using the File classThe class named File of the java.io package represents a file or directory (pathnames) in the system. This class provides various methods to perform various operations on files/directories.This class provides various methods to manipulate files, The rename() method of the File class accepts a String representing a ... Read More

How to read data from all files in a directory using Java?

Maruthi Krishna

Maruthi Krishna

Updated on 11-Sep-2019 14:04:20

11K+ Views

The class named File of the java.io package represents a file or directory (pathnames) in the system. This class provides various methods to perform various operations on files/directories.To get the list of all the existing files in a directory this class provides five different methods to get the details of ... Read More

How to read certain number of elements from a file in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 11-Sep-2019 13:59:07

615 Views

To read a fixed number of elements from a file you can either read a required number of data elements from the file and process them or, read the entire file into a collection or an array and process it for every n element.ExampleFollowing Java program, reads the contents of ... Read More

How do you upcast and downcast the same object in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 11-Sep-2019 07:22:54

234 Views

Converting one data type to others in Java is known as casting.Up casting − If you convert a higher datatype to lower datatype, it is known as narrowing (assigning higher data type value to the lower data type variable).Example Live Demoimport java.util.Scanner; public class NarrowingExample {    public static void main(String ... Read More

How to read data from PDF file and display on console in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 10-Sep-2019 13:44:22

10K+ Views

There are several libraries to read data from a pdf using Java. Let us see how to read data from a PDF document and display it on the console using a library named PDFBox.You can extract text using the getText() method of the PDFTextStripper class. This class extracts all the ... Read More

How to calculate String Buffer capacity in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 10-Sep-2019 13:38:26

824 Views

The String class of the java.lang package represents a set of characters. All string literals in Java programs, such as "abc", are implemented as instances of this class. Strings objects are immutable, once you create a String object you cannot change their values, if you try to do so instead ... Read More

Advertisements