Advertisement
Guest User

Untitled

a guest
Dec 13th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. package com.scalefocus;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.  
  7. public static void main(String[] args) {
  8. Scanner sc = new Scanner(System.in);
  9.  
  10. String path = sc.nextLine();
  11.  
  12. String fullFilename = path.substring(path.lastIndexOf('\\') + 1);
  13.  
  14. System.out.println(fullFilename);
  15.  
  16. int dotIndex = fullFilename.lastIndexOf('.');
  17. String extension = "";
  18. if(dotIndex!=-1) {
  19. extension = fullFilename.substring(dotIndex);
  20. }
  21.  
  22. String filename = fullFilename.replace(extension, "");
  23.  
  24. System.out.printf("File name: %s%n", filename);
  25. System.out.printf("Extension: %s%n", extension);
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement