View difference between Paste ID: CPV6z636 and z6VfbHM7
SHOW: | | - or go back to the newest paste.
1
import java.util.Scanner;
2
3
public class Demo {
4
    public static void main(String[] args) {
5
        Scanner scanner = new Scanner(System.in);
6
        String path = scanner.nextLine(); //"C:\Internal\training-internal\Template.pptx"
7
        String [] parts = path.split("\\\\");
8
        String fullFileName = parts[parts.length - 1];//"Template.pptx"
9
        String fileName = fullFileName.split("\\.")[0];
10
        String extension = fullFileName.split("\\.")[1];
11
12
        System.out.println("File name: " + fileName);
13
        System.out.println("File extension: " + extension);
14
15
16
    }
17
18
19
}