Computer Science, asked by Anonymous, 11 months ago

A Question Here......!
....
........
Write A Program to assign a full path and file name as given below.Using the library functions, extract an output, the file path, file name and file extension separately as shown:

INPUT...
C:\users\admin\pictures\

OUTPUT...
C:\users\admin\pictures\
File Name = Flower
Extension = jpg

....
.........
Give Proper Answers....!
No spams!!​

Answers

Answered by Anonymous
36

CODE :-

import java.util.*;

class Sample

{

public static void main(String args[])

{

Scanner sc=new Scanner(System.in);

System.out.println("Enter the path of file");

String s=sc.nextLine();

int a=s.lastIndexOf('\\');//backslash is an escape character

int b=s.lastIndexOf('.');

System.out.println("Path of the file is = "+s.substring(0,(a+1)));

System.out.println("File name is = "+s.substring((a+1),b));

System.out.println("Extension is = "+s.substring(b+1));

}

}

INPUT :-

C:\users\admin\pictures\Flower.jpg

OUTPUT :-

Path of the file is = C:\users\admin\pictures

File name is = Flowes

Extension is = jpg


Anonymous: Thanku Very Much
Anonymous: welcome
Similar questions