Maruthi Krishna has Published 951 Articles

How to compress a file in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 15-Oct-2019 10:06:59

4K+ Views

The DeflaterOutputStream class of Java is used to compress the given data and stream it out to the destination.The write() method of this class accepts the data (in integer and byte format), compresses it and, writes it to the destination of the current DeflaterOutputStream object. To compress a file using ... Read More

How to Get a slice of a primitive array in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 15-Oct-2019 09:25:21

726 Views

You can get a part of a Java array in between two specified indexes in various ways.By Copying contents:One way to do so is to create an empty array and copy the contents of the original array from the start index to the endIndex.Example Live Demoimport java.util.Arrays; public class SlicingAnArray { ... Read More

Difference between the list() and listFiles() methods in Java

Maruthi Krishna

Maruthi Krishna

Updated on 15-Oct-2019 08:09:11

688 Views

The class named File of the java.io package represents a file or directory (path names) in the system. To get the list of all the existing files in a directory this class provides the list() and ListFiles() methods.The main difference between them is thatThe list() method returns the names of ... Read More

Temporary files in Java

Maruthi Krishna

Maruthi Krishna

Updated on 15-Oct-2019 08:04:06

3K+ Views

In certain scenarios such as unit testing, or for some application logics you might need to create temporary files.Creating a temporary fileThe File class in Java provides a method with name createTempFile(). This method accepts two String variables representing the prefix (starting name) and suffix(extension) of the temp file and ... Read More

Reading data from keyboard using console class in Java

Maruthi Krishna

Maruthi Krishna

Updated on 15-Oct-2019 07:58:15

517 Views

The Console class is used to write/read data from the console (keyboard/screen) devices. It provides a readLine() method which reads a line from the key-board. You can get an object of the Console class using the console() method.Note − If you try to execute this program in a non-interactive environment ... Read More

Character streams in Java

Maruthi Krishna

Maruthi Krishna

Updated on 15-Oct-2019 07:53:34

6K+ Views

Character Streams − These handle data in 16 bit Unicode. Using these you can read and write text data only.The Reader and Writer classes (abstract) are the super classes of all the character stream classes: classes that are used to read/write character streams. Following are the character array stream classes ... Read More

Byte Streams in Java

Maruthi Krishna

Maruthi Krishna

Updated on 15-Oct-2019 07:51:15

4K+ Views

These handle data in bytes (8 bits) i.e., the byte stream classes read/write data of 8 bits. Using these you can store characters, videos, audios, images etc.The InputStream and OutputStream classes (abstract) are the super classes of all the input/output stream classes: classes that are used to read/write a stream ... Read More

What is the purpose of the flush() method of the BufferedWriter class in java?

Maruthi Krishna

Maruthi Krishna

Updated on 15-Oct-2019 07:44:38

297 Views

While you are trying to write data to a Stream using the BufferedWriter object, after invoking the write() method the data will be buffered initially, nothing will be printed.The flush() method is used to push the contents of the buffer to the underlying Stream.ExampleIn the following Java program, we are ... Read More

Converting String to StringBuilder in Java

Maruthi Krishna

Maruthi Krishna

Updated on 15-Oct-2019 07:38:52

411 Views

The append() method of the StringBuilder class accepts a String value and adds it to the current object.To convert a String value to StringBuilder object −Get the string value.Append the obtained string to the StringBuilder using the append() method.ExampleIn the following Java program, we are converting an array of Strings ... Read More

Removing leading zeros from a String using apache commons library in Java

Maruthi Krishna

Maruthi Krishna

Updated on 15-Oct-2019 07:31:57

2K+ Views

The stripStart() method of the org.apache.commons.lang.StringUtils class accepts two strings and removes the set of characters represented by the second string from the string of the first string.To remove leading zeros from a string using apache communal library −Add the following dependency to your pom.xml file    org.apache.commons    commons-lang3 ... Read More

Advertisements