forked from cs-dept-ibbul/java2019
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlabTwo_addressBreak.java
More file actions
29 lines (28 loc) · 928 Bytes
/
Copy pathlabTwo_addressBreak.java
File metadata and controls
29 lines (28 loc) · 928 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package practicalClass;
import java.util.Scanner;
//program to break file address into file path, file name and its extension
//U16/FNS/CSC/2061
public class labTwo_addressBreak {
public static void main(String[] args) {
Scanner file=new Scanner(System.in);
String path;
boolean check=false;
do {
System.out.println("Please enter File path: ");
path=file.nextLine();
if (path.contains("\\") && path.contains(".")) {
int index=path.lastIndexOf("\\");
int ext=path.lastIndexOf(".");
String fileName=path.substring(index+1, ext);
String filePath=path.substring(0, index);
String fileExt=path.substring(ext+1);
System.out.println("\nFor the full name: "+path);
System.out.println("Directory: "+filePath+" \nFile name: "+fileName+" \nExtension: "+fileExt);
check=true;
}
else {
System.out.println("Invalid Path ");
}
}while(!check);
}
}