Computer Applications
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\flower.jpg
Output
Path: C:\Users\admin\Pictures\
File name: flower
Extension: jpg
Java
Java String Handling
ICSE 2014
67 Likes
Answer
import java.util.Scanner;
public class KboatFilepathSplit
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter full path: ");
String filepath = in.next();
char pathSep = '\\';
char dotSep = '.';
int pathSepIdx = filepath.lastIndexOf(pathSep);
System.out.println("Path:\t\t" + filepath.substring(0, pathSepIdx));
int dotIdx = filepath.lastIndexOf(dotSep);
System.out.println("File Name:\t" + filepath.substring(pathSepIdx + 1, dotIdx));
System.out.println("Extension:\t" + filepath.substring(dotIdx + 1));
}
}
Output
![BlueJ output of 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\flower.jpg Output Path: C:\Users\admin\Pictures\ File name: flower Extension: jpg BlueJ output of 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\flower.jpg Output Path: C:\Users\admin\Pictures\ File name: flower Extension: jpg](https://cdn1.knowledgeboat.com/img/abp10/1/2014-p6-1.jpg)
Answered By
25 Likes
Related Questions
Which of the following returns a value greater than or equal to 0?
Consider the following program segment in which the statements are jumbled, choose the correct order of statements to check if a given word is Palindrome or not.
boolean palin(String w) { boolean isPalin; w = w.toUpperCase(); int l = w.length(); isPalin = false; // Stmt (1) for (int i = 0; i < l / 2; i++) { char c1 = w.charAt(i), c2 = w.charAt(l - 1 - i); // Stmt (2) if (c1 != c2) { break; // Stmt (3) isPalin = true; // Stmt (4) } } return isPalin; }
Define a class to accept the gmail id and check for its validity.
A gmail id is valid only if it has:
→ @
→ .(dot)
→ gmail
→ com
Example:
icse2024@gmail.com
is a valid gmail idThe output of a program which extracts a part of the string "SUBMISSION" is as follows:
(a) "MISS"
(b) "MISSION"If
String str = "SUBMISSION";
write appropriate Java statements to get the above outputs.