Samual Sam has Published 2492 Articles

Change a file attribute to read only in Java

Samual Sam

Samual Sam

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

616 Views

A file attribute can be changed to read-only by using the method java.io.File.setReadOnly(). This method requires no parameters and it returns true if the file is set to read-only and false otherwise. The method java.io.File.canWrite() is used to check whether the file can be written to in Java and if ... Read More

ftp_exec() function in PHP

Samual Sam

Samual Sam

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

165 Views

The ftp_exec() function is used to execute a command on the FTP server.Syntaxftp_exec(con, command)Parameterscon − The FTP connectioncommand − The command to execute.ReturnThe ftp_exec() function returns TRUE if the command was executed successfully, else FALSE.ExampleThe following is an example that executes a command on the FTP server −Read More

Displaying at most 10 characters in a string in Java

Samual Sam

Samual Sam

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

373 Views

To display at most 10 characters in a string, work with the Formatter class.Import the following package for Formatter class in Java −import java.util.Formatter;Create a new Formatter object −Formatter f = new Formatter();Let us now display at most 10 characters in a string −f = new Formatter(); System.out.println("Displaying at most ... Read More

Remove specified element from TreeSet in Java

Samual Sam

Samual Sam

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

146 Views

Use the remove() method to remove specified elements from TreeSet.At first, create a TreeSet and add elements −TreeSet set = new TreeSet(); set.add("34"); set.add("12"); set.add("67"); set.add("54"); set.add("76"); set.add("49");Now, remove the specified element i.e. 34 here −set.remove("34")The following is an example to remove specified element from TreeSet −Example Live Demoimport java.util.*; public ... Read More

ftp_fput() function in PHP

Samual Sam

Samual Sam

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

75 Views

The ftp_fget() function is used to upload from an open file and saves it to a file on the FTP server.Syntaxftp_fput(con, remote_file, open_file, mode, startpos);Parameterscon − The FTP connectionremote_file − The file path to upload toopen_file − The open local filemode − The transfer modestartpos − The position to begin ... Read More

Get Absolute path of a file in Java

Samual Sam

Samual Sam

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

2K+ Views

The method java.io.File.getAbsolutePath() is used to obtain the absolute path of a file in the form of a string. This method requires no parameters.A program that demonstrates this is given as follows −Example Live Demoimport java.io.File; public class Demo {    public static void main(String[] args) {       File ... Read More

Get the JVM uptime from RuntimeMXBean in Java

Samual Sam

Samual Sam

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

269 Views

RuntimeMXBean in the management interface for the runtime system of the Java virtual machine −RuntimeMXBean runtimeMX = ManagementFactory.getRuntimeMXBean();Let us get the JVM uptime using the getUptime() method −runtimeMX.getUptime()The following is an example −Example Live Demoimport java.lang.management.ManagementFactory; import java.lang.management.RuntimeMXBean; import java.util.Date; public class Demo { public static void main(String ... Read More

File Path with double slash in Java

Samual Sam

Samual Sam

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

1K+ Views

The double slash in the file path is required as to create the ’\’ character , another ‘\’ needs to be added to escape it. A program that demonstrates this is given as follows −Example Live Demoimport java.io.File; public class Demo {    public static void main(String[] args) {     ... Read More

Get Boot path from RuntimeMXBean in Java

Samual Sam

Samual Sam

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

127 Views

RuntimeMXBean in the management interface for the runtime system of the Java virtual machine.RuntimeMXBean runtimeMX = ManagementFactory.getRuntimeMXBean();To get the boot path, use the getBootClassPath() method −runtimeMX.getBootClassPath()The following is an example −Example Live Demoimport java.lang.management.ManagementFactory; import java.lang.management.RuntimeMXBean; import java.util.Date; public class Demo {    public static void main(String args[]) throws Exception { ... Read More

Search a particular element in a LinkedList in Java

Samual Sam

Samual Sam

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

166 Views

A particular element can be searched in a LinkedList using the method java.util.LinkedList.indexOf(). This method returns the index of the first occurance of the element that is searched. If the element is not available in the LinkedList, then this method returns -1.A program that demonstrates this is given as follows ... Read More

Advertisements