Samual Sam has Published 2310 Articles

Java Program to get the content of a directory

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:24

220 Views

The contents of a directory can be obtained using the method java.io.File.listFiles(). This method requires no parameters and it returns the abstract path names that specify the files and directories in the required directory.A program that demonstrates this is given as follows −Exampleimport java.io.File; public class Demo {    public ... Read More

Get byte array from BigInteger in Java

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:24

257 Views

First, set the BigInteger object with binary.BigInteger val = new BigInteger("100000000110001100000", 2);Now, use the toByteArray() method.byte[] byteArr = val.toByteArray();The following is an example −Example Live Demoimport java.math.BigInteger; public class Demo { public static void main(String[] argv) throws Exception { BigInteger val = ... Read More

Delete file or directory on termination in Java

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:24

286 Views

A file or directory can be deleted on termination of the program i.e. after the virtual machine terminates using the method java.io.File.deleteOnExit(). This method requires no parameters and it does not return a value.A program that demonstrates this is given as follows −Example Live Demoimport java.io.File; public class Demo {   ... Read More

ftp_rmdir() function in PHP

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:24

81 Views

The ftp_rmdir() function deletes a directory on the FTP server. Remember that the directory to be deleted should be empty.Syntaxftp_rmdir(conn, dir);Parametersconn −The FTP connectiondir − The empty directory to be deleted.ReturnThe ftp_rmdir() function returnsTRUE on success or FALSE on failure.ExampleThe following is an example −Read More

Java Program to round a double passed to BigDecimal

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:24

409 Views

The java.math.BigDecimal class provides operations for arithmetic, scale manipulation, rounding, comparison, hashing, and format conversion.Firstly, let us pass a double to BigDecimal −BigDecimal val = new BigDecimal(9.19456);Now, we will round it −val = val.setScale(2, BigDecimal.ROUND_HALF_EVEN);Above, we have used the field ROUND_HALF_EVEN. It is a rounding mode to round towards the ... Read More

Create a BigDecimal via string in Java

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:24

232 Views

Let us see how we can create BigDecimal values via string. Here, we have set string as a parameter to the BigDecimal constructor.BigDecimal val1 = new BigDecimal("375789755.345778656"); BigDecimal val2 = new BigDecimal("525678755.155778656");We can also perform mathematical operations on it −val2 = val2.subtract(val1);The following is an example −Example Live Demoimport java.math.BigDecimal; public ... Read More

ftp_site() function in PHP

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:24

76 Views

The ftp_site() function sends an FTP SITE command to the FTP server.Syntaxftp_site(conn, command);Parametersconn − The FTP connectioncommand − The SITE command. These commands vary from server to server and used in handling OS specific features such as file permissions and group membership.ReturnThe ftp_site() function returns TRUE on success or FALSE ... Read More

Subtract one BigDecimal from another BigDecimal in Java

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:24

511 Views

Use the subtract method to subtract one BigDecimal to another in Java. TheBigDecimal.subtract(BigDecimal val) returns a BigDecimal whose value is (this - subtrahend), and whose scale is max(this.scale(), subtrahend.scale()). Here, “val” is the value to be subtracted from this BigDecimal.The following is an example −Example Live Demoimport java.math.BigDecimal; public class Demo ... Read More

Display seconds with SimpleDateFormat('ss') in Java

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:24

1K+ Views

To work with SimpleDateFormat class in Java, import the following package.import java.text.SimpleDateFormat;Now, set the format with SimpleDateFormat(“ss”) to display seconds in two-digit.Format f = new SimpleDateFormat(”ss”);Now, get the seconds in a string −String strSeconds = f.format(new Date());The following is an example −Example Live Demoimport java.text.Format; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Calendar; ... Read More

ftp_ssl_connect() function in PHP

Samual Sam

Samual Sam

Updated on 30-Jul-2019 22:30:24

335 Views

The ftp_ssl_connect() function opens a secure SSL-FTP connection.Syntaxftp_ssl_connect(host, port, timeout);Parametershost − The FTP server address. Can be a domain address or an IP address.port − The port to connect to. Here the default is 21.timeout − The timeout for network operations.ReturnThe ftp_ssl_connect() function returns a SSL-FTP stream on success or ... Read More

Advertisements