当前位置: 首页>>代码示例>>Java>>正文


Java String.lastIndexOf方法代码示例

本文整理汇总了Java中java.lang.String.lastIndexOf方法的典型用法代码示例。如果您正苦于以下问题:Java String.lastIndexOf方法的具体用法?Java String.lastIndexOf怎么用?Java String.lastIndexOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.lang.String的用法示例。


在下文中一共展示了String.lastIndexOf方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: locateLocaleSpecificFileInClassPath

import java.lang.String; //导入方法依赖的package包/类
/**
 * locateLocaleSpecificFileInClassPath returns a DataInputStream that
 * can be used to read the requested file, but the name of the file is
 * determined using information from the current locale and the supplied
 * file name (which is treated as a "base" name, and is supplemented with
 * country and language related suffixes, obtained from the current
 * locale).  The CLASSPATH is used to locate the file.
 *
 * @param fileName The name of the file to locate.  The file name
 * may be qualified with a partial path name, using '/' as the separator
 * character or using separator characters appropriate for the host file
 * system, in which case each directory or zip file in the CLASSPATH will
 * be used as a base for finding the fully-qualified file.
 * Here is an example of how the supplied fileName is used as a base
 * for locating a locale-specific file:
 *
 * <pre>
 *     Supplied fileName: a/b/c/x.y,  current locale: US English
 *
 *                     Look first for: a/b/c/x_en_US.y
 *     (if that fails) Look next for:  a/b/c/x_en.y
 *     (if that fails) Look last for:  a/b/c/x.y
 *
 *     All elements of the class path are searched for each name,
 *     before the next possible name is tried.
 * </pre>
 *
 * @exception java.io.FileNotFoundException The requested class file
 * could not be found.
 * @exception java.io.IOException The requested class file
 * could not be opened.
 */
public static DataInputStream locateLocaleSpecificFileInClassPath (
    String fileName) throws FileNotFoundException, IOException {

    String localeSuffix = "_" + Locale.getDefault ().toString ();
    int lastSlash = fileName.lastIndexOf ('/');
    int lastDot   = fileName.lastIndexOf ('.');
    String fnFront, fnEnd;
    DataInputStream result = null;
    boolean lastAttempt = false;

    if ((lastDot > 0) && (lastDot > lastSlash)) {
        fnFront = fileName.substring (0, lastDot);
        fnEnd   = fileName.substring (lastDot);
    } else {
        fnFront = fileName;
        fnEnd   = "";
    }

    while (true) {
        if (lastAttempt)
            result = locateFileInClassPath (fileName);
        else try {
            result = locateFileInClassPath (fnFront + localeSuffix + fnEnd);
        } catch (Exception e) { /* ignore */ }
        if ((result != null) || lastAttempt)
            break;
        int lastUnderbar = localeSuffix.lastIndexOf ('_');
        if (lastUnderbar > 0)
            localeSuffix = localeSuffix.substring (0, lastUnderbar);
        else
            lastAttempt = true;
    }
    return result;

}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:68,代码来源:FileLocator.java


注:本文中的java.lang.String.lastIndexOf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。