desislava_topuzakova

03. Extract File

Jul 26th, 2021
1,296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.59 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment