Maruthi Krishna has Published 870 Articles

How to list all files (only) from a directory using Java?

Maruthi Krishna

Maruthi Krishna

Updated on 08-Feb-2021 11:13:47

3K+ Views

The ListFiles() method returns an array holding the objects (abstract paths) of all the files (and directories) in the path represented by the current (File) object.The File Filter interface is filter for the path names you can pass this as a parameter to the listFiles() method. This method filters the ... Read More

How to read all files in a folder to a single file using Java?

Maruthi Krishna

Maruthi Krishna

Updated on 08-Feb-2021 11:10:12

9K+ Views

The listFiles() method of the File class returns an array holding the objects (abstract paths) of all the files (and directories) in the path represented by the current (File) object.To read the contents of all the files in a folder into a single file −Create a file object by passing ... Read More

How to search a file in a directory in java

Maruthi Krishna

Maruthi Krishna

Updated on 08-Feb-2021 11:09:15

4K+ Views

The List() method of the File class returns a String array containing the names of all the files and directories in the path represented by the current (File) object.In order to search for a file you need to compare the name of each file in the directory to the name ... Read More

How to get the list of jpg files in a directory in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 08-Feb-2021 11:06:23

1K+ Views

The String[] list(FilenameFilter filter) method of a File class returns a String array containing the names of all the files and directories in the path represented by the current (File) object. But the retuned array contains the filenames which are filtered based on the specified filter. The FilenameFilter is an interface in ... Read More

How to create Directories using the File utility methods in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 08-Feb-2021 11:05:09

382 Views

Since Java 7 the File.02s class was introduced this contains (static) methods that operate on files, directories, or other types of files.The createDirectory() method of the Files class accepts the path of the required directory and creates a new directory.ExampleFollowing Java example reads the path and name of the directory to be created, ... Read More

How to convert primitive data into wrapper class using Java?

Maruthi Krishna

Maruthi Krishna

Updated on 06-Feb-2021 04:37:48

1K+ Views

Java provides certain classes called wrapper classes in the java.lang package. The objects of these classes wrap primitive datatypes within them.Using wrapper classes, you can also add primitive datatypes to various Collection objects such as ArrayList, HashMap etc. You can also pass primitive values over network using wrapper classes.ExampleLive Demoimport ... Read More

How to inherit multiple interfaces in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 06-Feb-2021 04:34:58

471 Views

An interface in Java is similar to class but, it contains only abstract methods and fields which are final and static.Just like classes you can extend one interface from another using the extends keyword. You can also extend multiple interfaces from an interface using the extends keyword, by separating the ... Read More

What is Java reg ex to check for date and time?

Maruthi Krishna

Maruthi Krishna

Updated on 06-Feb-2021 04:32:21

2K+ Views

To match a regular expression with the given string You need to:.Compile the regular expression of the compile() method of the Pattern class.Get the Matcher object bypassing the required input string as a parameter to the matcher() method of the Pattern class.The matches() method of the Matcher class returns true ... Read More

How to get Time in Milliseconds for the Given date and time in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 06-Feb-2021 04:31:49

2K+ Views

The java.text.SimpleDateFormat class is used to format and parse a string to date and date to string.One of the constructors of this class accepts a String value representing the desired date format and creates SimpleDateFormat object. To parse/convert a string as a Date object Instantiate this class by passing desired format string.Parse ... Read More

How to get current date/time in milli seconds in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 06-Feb-2021 04:29:11

7K+ Views

The getTime() method of the Date class retrieves and returns the epoch time (number of milliseconds from Jan 1st 1970 00:00:00 GMT0.ExampleLive Demoimport java.util.Date; public class Sample {    public static void main(String args[]){         //Instantiating the Date class       Date date = new Date(); ... Read More

Previous 1 ... 7 8 9 10 11 ... 87 Next
Advertisements