0 votes
in JAVA by

What is getname in java with example?

1 Answer

0 votes
by

What is getname in java with example?

import java.io.*; 

  

public class solution { 

    public static void main(String args[]) 

    { 

  

        // try-catch block to handle exceptions 

        try { 

  

            // Create a file object 

            File f = new File(""new.txt""); 

  

            // Get the Name of the given file f 

            String Name = f.getName(); 

  

            // Display the file Name of the file object 

            System.out.println(""File Name : "" + Name); 

        } 

        catch (Exception e) { 

            System.err.println(e.getMessage()); 

        } 

    } 

getName returns the name of the file.

🔗Reference: stackoverflow.com

🔗Source: Java Interview Questions and Answers

...