desislava_topuzakova

03. Extract File

Nov 12th, 2021
1,431
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.85 KB | None | 0 0
  1. package TextProcessing_Exercise;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class ExtractFile_03 {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         String fullPathFile = scanner.nextLine();
  9.         //C:\Internal\training-internal\Template.pptx
  10.         //.split("\")
  11.         String [] pathParts = fullPathFile.split("\\\\");
  12.         //["C:", "Internal", "training-internal", "Template.pptx"]
  13.         //1. пълното име на файла
  14.         String fullFileName = pathParts[pathParts.length - 1]; //"Template.pptx"
  15.         //.split(".") -> ["Template", "pptx"]
  16.         String fileName = fullFileName.split("\\.")[0];
  17.         String extension = fullFileName.split("\\.")[1];
  18.  
  19.         System.out.println("File name: " + fileName);
  20.         System.out.println("File extension: " + extension);
  21.  
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment