StringTokenizer example
===============================================
package testjava;
import java.io.File;
import java.util.StringTokenizer;
public class TStringTokenizer {
public static void main(String[] args) {
//The following is one example of the use of the tokenizer. The code:
File curDir ;
String fileName = "";
String chkFile = "";
try {
curDir = new File(System.getProperty("user.dir")+System.getProperty("file.separator")+"src"+System.getProperty("file.separator")+"testjava");
for(File f : curDir.listFiles()){
fileName = f.getName().toLowerCase();
StringTokenizer st = new StringTokenizer(fileName , ".");
while(st.hasMoreTokens()){
st.nextToken();
if(st.countTokens()== 1){
chkFile = st.nextToken().toLowerCase();
}
}//while
if("jpg".equals(chkFile)||"jpeg".equals(chkFile))
System.out.println("ok jpg");
else
System.out.println("is not jpg : "+fileName);
}//for
} catch (Exception e) {
// TODO: handle exception
}
}
}
------------------------------------------------------------------
result :
is not jpg : inqueryelevatorvo.java
is not jpg : tstringtokenizer.java
result :
is not jpg : inqueryelevatorvo.java
is not jpg : tstringtokenizer.java