Advertisement
egencheva

03.Extract File

Mar 24th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.63 KB | None | 0 0
  1. package TextProcessingAndRegEx;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class ExtractFile {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         String input = scanner.nextLine();
  10.         int index = input.lastIndexOf("\\");
  11.  
  12.  
  13.         String file = input.substring(index + 1);
  14.         int index2 = file.lastIndexOf(".");
  15.  
  16.         String fileType =file.substring(index2+1);
  17.         String fileName =file.substring(0,index2);
  18.  
  19.         System.out.println(String.format("File name: %s",fileName));
  20.         System.out.println(String.format("File extension: %s",fileType));
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement