Didart

Extract File

Nov 12th, 2021
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.57 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class ExtractFile {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         String fullPathFile = scanner.nextLine();
  8.  
  9.         String[] pathParts = fullPathFile.split("\\\\");
  10.  
  11.         String fullFileName = pathParts[pathParts.length - 1];
  12.  
  13.         String fileName = fullFileName.split("\\.")[0];
  14.         String extension = fullFileName.split("\\.")[1];
  15.  
  16.         System.out.println("File name: " + fileName);
  17.         System.out.println("File extension: " + extension);
  18.        
  19.     }
  20. }
  21.  
Advertisement
Add Comment
Please, Sign In to add comment