Server Side Programming Articles

Page 1984 of 2109

How to search a directory with file extensions in Java?

Maruthi Krishna
Maruthi Krishna
Updated on 08-Feb-2021 1K+ Views

Following example prints the files in a directory based on the extensions −Exampleimport java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.stream.Stream; public class Demo {    public static void main(String[] args) throws IOException {       Stream path = Files.walk(Paths.get("D:\ExampleDirectory"));       System.out.println("List of PDF files:");       path = path.filter(var -> var.toString().endsWith(".pdf"));       path.forEach(System.out::println);             path = Files.walk(Paths.get("D:\ExampleDirectory"));       System.out.println("List of JPG files:");       path = path.filter(var -> var.toString().endsWith(".jpg"));       path.forEach(System.out::println);           path = Files.walk(Paths.get("D:\ExampleDirectory"));       ...

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 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

How to check for duplicates in data.table object in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 08-Feb-2021 610 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

Read More

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

Maruthi Krishna
Maruthi Krishna
Updated on 08-Feb-2021 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

How to change the first value for each group in data.table object in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 08-Feb-2021 791 Views

To change the first value for each group in data.table object, we can use single square brackets for accessing and changing the value to desired value. For example, if we have a data.table object called DT that contains a group column defined by Class and a numerical column defined by Response then the first value of Response for each Class can be set to say 5 by using the command DT[,Response:=c(2,Response[-]),by=Class]Consider the below data.table object −Examplelibrary(data.table) Group

Read More

How to create a plot of binomial distribution in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 08-Feb-2021 2K+ Views

A binomial distribution is based on the distribution of success and failure, the other two parameters of binomial distribution are the sample size and the probability of success. To create a plot of binomial distribution, we first need to define the density of the binomial distribution using dbinom function. The plotting can be done by using plot function with success and the density as shown in the below examples.Examplex

Read More

How to deal with missing column for row names when converting data frame to data.table object in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 08-Feb-2021 577 Views

To deal with missing column of row names when converting data frame in R to data.table object, we need to use keep.rownames argument while converting the data frame. For example, if we have a data frame called df that needs to be converted to a data.table object without missing row names then we can use the below command −data.table(df,keep.rownames=TRUE)Examplelibrary(data.table) head(mtcars)Output            mpg     cyl    disp   hp    drat     wt      qsec   vs     am   gear carb Mazda RX4    21.0    6     160    110    3.90   2.620     16.46  0      1    4     4 Mazda RX4 Wag 21.0   6     160   110   3.90   2.875     17.02    0      1    4     4 Datsun     710      22.8   4    108 93 3.85   2.320    18.61     1      1    4     1 Hornet 4 Drive 21.4    6   258  110   3.08     3.215     19.44   1      0    3     1 Hornet Sportabout 18.7  8  360  175  3.15     3.440      17.02   0      0    3     2 Valiant      18.1    6    225  105   2.76     3.460      20.22   1      0    3     1Examplemtcars_data_table

Read More

How to remove the plot margin in base R between the axes and the points inside the plot?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 08-Feb-2021 1K+ Views

To remove the plot margin in base R between the axes and the points inside the plot, we can use xaxs and yaxs argument in plot function. Depending on the choices of the arguments xaxs and yaxs, the plot region in the respective direction is 4% larger than specified by these limits or exactly matches the "i" limits.Examplex

Read More

How to increase the thickness of histogram lines in base R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 08-Feb-2021 2K+ Views

To increase the thickness of histogram lines in base R, we would need to use par function by defining the thickness size of the line. If we want to do so then line thickness must be defined first before creating the histogram. An example of line size could be line

Read More

How to create a cumulative sum plot in base R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 08-Feb-2021 4K+ Views

To create a cumulative sum plot in base R, we can simply use plot function. For cumulative sums inside the plot, the cumsum function needs to be used for the variable that has to be summed up with cumulation. For example, if we have two vectors say x and y then the plot with cumulative sum plot can be created as plot(x,cumsum(y)).Examplex1

Read More
Showing 19831–19840 of 21,090 articles
Advertisements