/* eg : INPUT --> "C:/program files/new program/path/show path/example.prg"
----------------------------------------------------------------------------
OUTPUT:
PATH --> C:/program files/new program/path/show path/
FILE NAME --> example
EXTENSION --> prg
*/
import java.util.*;//I am using Scanner class to take the input
class location
{
Scanner in = new Scanner(System.in);
void main()
{
System.out.println("Enter the Location of a file");
String p = in.next();//to input the location
int index_file = p.lastIndexOf('/');//to store the last index of '/' in the location
String file_with_extention = p.substring(index_file+1);//to store the file and extention
int index_dot = file_with_extention.lastIndexOf('.');//to sore the last index of '.' in order to find the extention
String path = p.substring(0,index_file+1);//to take out the path of the file
String extension = file_with_extention.substring(index_dot+1);//to sore the extension of the file
String file = file_with_extention.substring(0,index_dot);//to store the name of file
System.out.println("Path: "+path);
System.out.println("File Name: "+file);
System.out.println("Extension: "+extension);
}
}
----------------------------------------------------------------------------
OUTPUT:
PATH --> C:/program files/new program/path/show path/
FILE NAME --> example
EXTENSION --> prg
*/
import java.util.*;//I am using Scanner class to take the input
class location
{
Scanner in = new Scanner(System.in);
void main()
{
System.out.println("Enter the Location of a file");
String p = in.next();//to input the location
int index_file = p.lastIndexOf('/');//to store the last index of '/' in the location
String file_with_extention = p.substring(index_file+1);//to store the file and extention
int index_dot = file_with_extention.lastIndexOf('.');//to sore the last index of '.' in order to find the extention
String path = p.substring(0,index_file+1);//to take out the path of the file
String extension = file_with_extention.substring(index_dot+1);//to sore the extension of the file
String file = file_with_extention.substring(0,index_dot);//to store the name of file
System.out.println("Path: "+path);
System.out.println("File Name: "+file);
System.out.println("Extension: "+extension);
}
}
No comments:
Post a Comment