Programming Articles - Page 2861 of 3368

Java Program to check whether a file exists or not

Samual Sam
Updated on 23-Nov-2024 03:51:25

276 Views

In this article, we will learn how to check whether a file exists using Java. The program demonstrates the use of the exists() method from the java.io.File class to perform this check. Java.io.File.exists() MethodThe java.io.File.exists() method returns true if the file path exists, otherwise it returns false. Parameters: This method does not take any parameters. Return Value: It returns a boolean indicating whether the file specified by the abstract path exists. Checking whether a file exists or not in Java The following are the steps to check whether a file exists or not − Step 1. ... Read More

Get the String representation of the current File object in Java

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

227 Views

The string representation of the current file object can be obtained using the method java.io.File.toString(). This method returns the abstract path name in the string form.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 file = new File("C:" + File.separator + "jdk11.0.2" + File.separator, "demo1.java");       System.out.println("File: " + file.toString());    } }The output of the above program is as follows −OutputFile: C:/jdk11.0.2/demo1.javaNow let us understand the above program.The abstract path name is printed in the string form using the ... Read More

Java program to get the name of the parent directory of the file or directory

Samual Sam
Updated on 10-Oct-2024 11:36:47

926 Views

In this program, we will demonstrate how to retrieve the parent directory of a file using the File class in Java. The name of the parent directory of the file or directory can be obtained using the method getParent() method using the java.io package. This method returns the parent directory path name string or null if there is no parent named. Steps to get the name of the parent directory Following are the steps to get the name of the parent directory − We will start by importing the java.io.File class. Create a ... Read More

Check if the File object refers to an absolute pathname in Java

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

534 Views

The method java.io.File.isAbsolute() is used to check if the file object refers to an absolute pathname. This method returns true if the abstract path name is absolute and false if the abstract path name is not absolute.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 file = new File("C:" + File.separator + "jdk11.0.2" + File.separator, "demo1.java");       System.out.println(file.isAbsolute());    } }The output of the above program is as follows −OutputfalseNow let us understand the above program.The isAbsolute() method is used ... Read More

Get the name of the file and path in Java

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

7K+ Views

The name of the file and the name of the path can be obtained using the methods java.io.File.getName() and java.io.File.getPath() respectively. The getName() returns the name of the file or the directory. The getPath() returns the abstract pathname in the form of a pathname string.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 file = new File("C:" + File.separator + "jdk11.0.2" + File.separator, "demo1.java");       System.out.println("File name: " + file.getName());       System.out.println("Path name: " + file.getPath());    } ... Read More

imagecreatetruecolor() function in PHP

Arjun Thakur
Updated on 31-Dec-2019 08:05:48

939 Views

The imagecreatetruecolor() function creates a new true color image.Syntaximagecreatetruecolor (width , height )Parameterswidth: The image width.height: The image height.ReturnThe imagecreatetruecolor() function returns an image resource identifier on success, FALSE on errors.ExampleThe following is an example Live DemoOutputThe following is the output displaying the height and width of the new image:500 600ExampleLet us see another example with different height and width: Live DemoOutputThe following is the output displaying the height and width of the new image:450 300

imageconvolution() function in PHP

Chandu yadav
Updated on 31-Dec-2019 08:00:58

150 Views

The imageconvolution() functionSyntaxbool imageconvolution (img, matrix, div, offset )Parametersimg: Create image with imagecreatetruecolor() function.matrix: A 3x3 matrix is an array of three arrays of three floats.div: Divisor of the result of the convolution, used for normalization.offset: The color offset.ReturnThe imageconvolution() function returns True on success or False on failure.ExampleThe following is an exampleOutputThe following is the outputExampleLet us see another example with different parameter values for the same image. You can easily spot the difference now:OutputThe following is the output

imagecolormatch() function in PHP

Ankith Reddy
Updated on 31-Dec-2019 07:59:35

82 Views

The imagecolormatch() function forms the colors of the palette version of an image more closely match the true color versionSyntaxbool imagecolormatch ( img1, img2 )Parametersimg1: Create image with imagecreatetruecolor() function.img2: A palette image link resource pointing to an image. This image has the same size as img1.ReturnThe imagecolormatch() function returns TRUE on success or FALSE on failure.ExampleThe following is an example Live DemoOutputThe following is the output:1ExampleLet us see another example Live DemoOutputThe following is the output:1

imagecolortransparent() function in PHP

George John
Updated on 31-Dec-2019 07:58:19

334 Views

The imagecolortransparent() function is used to set the color of a transparent image.Syntaximagecolortransparent ( img, color )Parametersimg: Create image with imagecreatetruecolor() function.color: Color identifier created with imagecolorallocate().ReturnThe imagecolortransparent() function returns the identifier of the new transparent color. The return value is -1 if color is not specified and the image has no transparent color.ExampleThe following is an exampleOutputThe following is the output:

imagecolorresolve() function in PHP

Arjun Thakur
Updated on 31-Dec-2019 07:48:35

36 Views

The imagecolorresolve() function gets the index of the specified color or its closest possible alternative.Syntaximagecolorresolve (img , red , green , blue )Parametersimg: Image created with imagecreatetruecolor() function.red: The value of red component.green: The value of green component.blue: The value of blue component.ReturnThe imagecolorresolve() function returns the color index.ExampleThe following is an example Live DemoOutputThe following is the output:Array ( [0] => 128 [1] => 129 [2] => 130 )

Advertisements