Title

JAVA

      In this blog, you will find programs on JAVA and also some help on how to write programs for JAVA...

December 18, 2014

WAP to get the full path of a file. Extract the file path, file name & extension.

Sample Input:
Enter the path: C:\Users\User\Pictures\Ferrai.jpeg

Sample Output:
Path: C:\Users\User\Pictures\
Name: Ferrai
Extention: jpeg


import java.util.Scanner;
public class Path
{
    public static void main()
    {
        Scanner s=new Scanner(System.in);
        System.out.print("Enter the path: ");
        String str=s.nextLine();
        String a[]=str.split("\\\\");
        String b[]=a[a.length-1].split("\\.");
        String f="";
        for(int x=0; x<a.length-1; x++)
            f=f+a[x]+"\\";
        System.out.println("Path: " + f);
        System.out.println("Name: " + b[0]);
        System.out.println("Extention: " + b[1]);
    }
}

No comments:

Post a Comment

Please write your comment in the box below...