Write a program to assign a full path and file name as given below. Using library functions, extract and output the file path, file name and file extension separately as shown.
Input: C:\Users\admin\Pictures\flowers.jpg
Output:
Path: C:\Users\admin\Pictures\
File name: flower
Extension: jpg
import java.io.*;
class File
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader (new InputStreamReader(System.in));
System.out.print("Enter the full path of the file : ");
String s = br.readLine();
int x = s.lastIndexOf('\\'); // Finding position of last backward slash
int y = s.lastIndexOf('.'); // Finding position of last '.'
String path = s.substring(0,(x+1));
String file = s.substring((x+1),y);
String extn = s.substring((y+1));
System.out.println("Output :");
System.out.println("Path : "+path);
System.out.println("File Name : "+file);
System.out.println("Extension : "+extn);
}
}
Input: C:\Users\admin\Pictures\flowers.jpg
Output:
Path: C:\Users\admin\Pictures\
File name: flower
Extension: jpg
import java.io.*;
class File
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader (new InputStreamReader(System.in));
System.out.print("Enter the full path of the file : ");
String s = br.readLine();
int x = s.lastIndexOf('\\'); // Finding position of last backward slash
int y = s.lastIndexOf('.'); // Finding position of last '.'
String path = s.substring(0,(x+1));
String file = s.substring((x+1),y);
String extn = s.substring((y+1));
System.out.println("Output :");
System.out.println("Path : "+path);
System.out.println("File Name : "+file);
System.out.println("Extension : "+extn);
}
}