本文整理匯總了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;
}