Friday, May 13, 2016

Get the file Name from the Path using java.nio.file.Paths API



Code Snippet : 

import java.nio.file.Path;
import java.nio.file.Paths;


public class GetFileName {

       public static void main(String[] args) {
              String filePath = "MESSAGE_PATH";
              Path p = Paths.get(filePath);
              String fileName = p.getFileName().toString();
              int index = fileName.indexOf(".");
              String mainChapterNumber = fileName.substring(0,index);
              System.out.println(mainChapterNumber);
       }


}

No comments:

Post a Comment