从末尾提取顶级类名称剪切“ .java”。
//nowjava.com - 时代Java 提 供 //package com.nowjava; import java.io.File; public class Main { public static void main(String[] argv) throws Exception { String sourceFile = "nowjava.com"; System.out.println(getTopLevelClassName(sourceFile)); } /** * Extract top level class name cutting ".java" from the end. * * @param sourceFile * * @return */ public static String getTopLevelClassName(final String sourceFile) { String className = sourceFile.substring(0, sourceFile.length() - 5);