List All Files from a Directory Using Java

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 file names passed on the passed filter.To get the files in a folder implement a FileFilter which accepts only files and pass it as a parameter to the listFiles() method.Following is a screen shot of the contents of the ExampleDirectoryExampleimport java.io.File; import java.io.FileFilter; import java.io.IOException; public class Demo{    public ... Read More

Increase X-Axis Length of Histogram in Base R

Nizamuddin Siddiqui
Updated on 08-Feb-2021 11:11:14

6K+ Views

To increase the X-axis length of histogram in base R, we can use the axis function. The most important thing to remember while using the axis function is mentioning the appropriate sequence based on the values in the vector or in the column of the data frame if a data frame is used.Example Live Demox

Read All Files in a Folder to a Single File Using Java

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 the required file path as a parameter.Read the contents of each file using Scanner or any other reader.Append the read contents into a StringBuffer.Write the StringBuffer contents into the required output file.Exampleimport java.io.DataOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.util.Scanner; public class Test {    public static void main(String ... Read More

Check for Duplicates in Data Table Object in R

Nizamuddin Siddiqui
Updated on 08-Feb-2021 11:09:55

571 Views

The checking for duplicates in a data.table object can be easily done with the help of delta ($) operator that is used to access the columns and the duplicated function. For example, if a data.table object DT contains a column x then to check the duplicates in x, we can use the command duplicated(DT$x).Example1Loading data.table object and creating an object −library(data.table) set.seed(141) x

Create Combination of Pairs from a Vector in R

Nizamuddin Siddiqui
Updated on 08-Feb-2021 11:09:34

3K+ Views

To create a combination of pairs, we can use the combn function. This function will be helpful to use the vector length and the value 2 that represents a pair to create the combinations. Although, this is enough but we can transpose the output to get a better−looking output.Example1 Live Demox1

Search a File in a Directory in Java

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 of the required file using the equals() method.ExampleLive Demoimport java.io.File; import java.util.Arrays; import java.util.Scanner; public class Example {    public static void main(String[] argv) throws Exception {       System.out.println("Enter the directory path: ");       Scanner sc = new Scanner(System.in);       String pathStr = sc.next(); ... Read More

Get List of JPG Files in a Directory in Java

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 Java with a single method.accept(File dir, String name)To get the file names based on extensions implement this interface as such and pass its object to the above specified list() method of the file class.Assume we have a folder named ExampleDirectory in the directory D with 7 files and 2 directories ... Read More

Multiply One Column in an R Data Frame with a Number

Nizamuddin Siddiqui
Updated on 08-Feb-2021 11:06:03

4K+ Views

To multiply only one column with a number, we can simply use the multiplication operator * but need to replace the original column with the new values. For example, if we have a data frame called df that contains three columns x1, x2, and x3, and we want to multiply the second column x2 with 2 then it can be done as df$x2

Create Directories Using File Utility Methods in Java

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

413 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, from the user, and creates it.Live Demoimport java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Scanner; public class Test {    public static void main(String args[]) throws IOException {       System.out.println("Enter the path to create a directory: ");       Scanner sc = new Scanner(System.in);     ... Read More

Check If a String Contains a Specific Word

Chirag Nagrekar
Updated on 08-Feb-2021 07:55:01

1K+ Views

To check if the PowerShell string contains a specific word, we can use the string method Contains(). For example, ExamplePS C:\> $str = 'TestNZ01LT' PS C:\> $str.Contains('NZ') TrueNow the funny thing is, even if the PowerShell is case-Insensitive, the above command is not. We need to provide the exact substring. For example, the below output will be false.ExamplePS C:\> $str.Contains('Nz') FalseTo overcome this problem, we can either provide the same search name in the method or we need to use the lowercase or uppercase method if you don’t want the search case-sensitive.PS C:\> $str = 'TestNZ01LT' PS C:\> ($str.ToLower()).Contains(('Nz').ToLower()) True ... Read More

Advertisements