String latter = name.substring(name.lastIndexOf(".") + 1); //不包括".",比如"java",而不是".java"
将文件中的内容读入到String数组中——
BufferedReader br = null; try{ br = new BufferedReader(new FileReader(fileName)); }catch(Exception e){ System.out.println("Error! Opening new buffer for file fails!"); } String tmpString = null; // A good way to read a file and convert to a string StringBuffer sb = new StringBuffer(); try { while ((tmpString = br.readLine()) != null) { sb.append(tmpString); //read the file context into stringbuffer sb.append('\n'); //readLine会忽略行尾的\n,我们手动加上,一会儿作为单词分割的“分割词” } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }
String [] words = sb.toString().split(",|\\.|\\?|:|!|\\n|\\t| "); // result in blank string when appear together // String [] test = sb.toString().split("(,|\\.|\\?|:|!|\\n|\\t| )+"); //TODO: won't appear so many blank string List<String> l = new ArrayList<String>(); // A good way to delete special element in array for(String s : words){ l.add(s); } while(l.contains("")){ l.remove(""); } words = l.toArray(new String [l.size()]); //用l中的元素为内容创建数组,再进行元素复制,但由于返回类型是Object[],所以进行显式转换。
ArrayList<WordInfo> al = CountTxt.hashMap.get(CountTxt.word); al.sort(new FrequencyComparator());
import java.util.Timer; import java.util.TimerTask; public class M { public static void main(String[] args) { // TODO todo.generated by zoer Timer timer = new Timer(); timer.schedule(new MyTask(), 1000, 2000); } } class MyTask extends TimerTask { @Override public void run() { System.out.println("dddd"); } }
原文地址:http://blog.csdn.net/puppylpg/article/details/45874589