Input C: / Users / admin / Pictures / flower.jpg
Output path: C: / Users/admin/Pictures/
File name: flower
Extension: jpg
import java.util.*;
class Ab
{
String str1,str2,str3;
int i;
Scanner sc=new Scanner(System.in);
public void take()
{
System.out.print("\nEnter the file name with extension and complete path:");
str1=sc.nextLine();
i=str1.lastIndexOf('/');
str2=str1.substring(0,i+1);
System.out.print("\nPath of the file:"+str2);
str2=str1.substring(i+1);// flower.jpg
i=str2.indexOf('.');
str3=str2.substring(0,i);
str2=str2.substring(i+1);
System.out.print("\n\nFile Name="+str3 + " Extension="+str2);
}
}
Sample Input Output
Enter the file name with extension and complete path:C:/my folder/new folder/flower.jpg
Path of the file:C:/my folder/new folder/
File Name=flower Extension=jpg
No comments:
Post a Comment