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
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
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
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
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
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
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
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
To convert any command output to the hashtable in PowerShell, we can first convert the output to the JSON format using the ConvertTo-JSON command, and applying the ConvertFrom-JSON command from the first output will produce an output to the Hashtable.ExampleGet-ServiceThe above command will give the output in the array format.OutputStatus Name DisplayName ------ ---- ----------- Stopped WwanSvc WWAN AutoConfig Stopped XblAuthManager Xbox Live Auth Manager Stopped XblGameSave Xbox Live Game Save Stopped XboxGipSvc Xbox Accessory Management Service Stopped XboxNetApiSvc Xbox Live ... Read More
When we write Invoke-Command in PowerShell, sometimes we get the RunSpaceID property in PowerShell. This is because we use Select-Object (alias: Select) command inside the scriptblock. For example,ExampleInvoke-Command -ComputerName LabMachine2k12 -ScriptBlock{Get-Process PowerShell | Select Name, CPU, WorkingSet}OutputName : powershell CPU : 9.1572587 WorkingSet : 127700992 PSComputerName : LabMachine2k12 RunspaceId : c690f205-06d4-4cc4-be29-5302725eadf1To avoid getting the RunSpaceID property in the output, use the Select command output the scriptblock. For example,ExampleInvoke-Command -ComputerName LabMachine2k12 -ScriptBlock{Get-Process PowerShell} | Select Name, CPU, WorkingSetOutputName CPU WorkingSet ---- --- ---------- powershell 9.1572587 127700992
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP