Found 9326 Articles for Object Oriented Programming

Check whether the file is hidden or not in Java

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

492 Views

The method java.io.File.isHidden() is used to check whether the given file specified by the abstract path name is a hidden file in Java. This method returns true if the file specified by the abstract path name is hidden and false otherwise.A program that demonstrates this is given as follows −Example Live Demoimport java.io.File; public class Demo {    public static void main(String[] args) {       try {          File file = new File("demo1.txt");          file.createNewFile();          System.out.println("Is file hidden? " + file.isHidden());       } catch(Exception e) {   ... Read More

Check whether the given file is an existing file in Java

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

96 Views

The method java.io.File.isFile() is used to check whether the given file specified by the abstract path name is an existing file in Java. This method returns true if the file specified by the abstract path name is a file and false otherwise.A program that demonstrates this is given as follows −Example Live Demoimport java.io.File; public class Demo {    public static void main(String[] args) {       try {          File file = new File("demo1.txt");          file.createNewFile();          System.out.println("Is file? " + file.isFile());       } catch(Exception e) {   ... Read More

Check whether a file is a directory in Java

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

4K+ Views

The method java.io.File.isDirectory() checks whether a file with the specified abstract path name is a directory or not. This method returns true if the file specified by the abstract path name is a directory and false otherwise.A program that demonstrates this is given as follows −Example Live Demoimport java.io.File; public class Demo {    public static void main(String[] args) {       try {          File file = new File("demo1.txt");          file.createNewFile();          System.out.println("Is directory? " + file.isDirectory());       } catch(Exception e) {          e.printStackTrace();   ... Read More

Java Program to check whether a file exists or not

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

174 Views

The method java.io.File.exists() is used to check whether a file exists or not. This method returns true if the file specified by the abstract path name exists and false if it does not exist.A program that demonstrates this is given as follows −Example Live Demoimport java.io.File; public class Demo {    public static void main(String[] args) {       try {          File file = new File("demo1.txt");          file.createNewFile();          System.out.println("File exists? " + file.exists());       } catch(Exception e) {          e.printStackTrace();       } ... Read More

Get the String representation of the current File object in Java

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

149 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 30-Jul-2019 22:30:24

541 Views

The name of the parent directory of the file or directory can be obtained using the method java.io.File.getParent(). This method returns the parent directory path name string or null if there is no parent named.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);       System.out.println("Parent: " + file.getParent());    } }The output of the above program is as follows −OutputFile: C:/jdk11.0.2/demo1.java Parent: ... Read More

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

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

290 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

6K+ 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

Detection of ambiguous indentation in python

Arjun Thakur
Updated on 30-Jun-2020 09:27:06

419 Views

Indentation is an important feature of Python syntax. Code blocks in function, class or loops are required to follow same indent level for statements in it. The tabnanny module in Python's standard library is able to detect any violation in this stipulation.This module is primarily intended to be used in command line mode with –m switch. However, it can also be imported in an interpreter session.Command line usagepython –m tabnanny –q example.pyFor verbose output use –v switchpython –m tabnanny –v example.pyFollowing functions are defined in tabnanny module for checking indentation programmatically.check()This function checks for ambiguously indented lines in a given ... Read More

Name validation using Java Regular Expressions

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

996 Views

The name can be validated using the java.util.regex.Pattern.matches() method. This method matches the regular expression for the name and the given input name and returns true if they match and false otherwise.A program that demonstrates this is given as follows:Example Live Demopublic class Demo {    public static void main(String args[]) {       String name = "John Harry Smith";       String regexName = "\p{Upper}(\p{Lower}+\s?)";       String patternName = "(" + regexName + "){2, 3}";       System.out.println("The name is: " + name);       System.out.println("Is the above name valid? " + name.matches(patternName));   ... Read More

Advertisements