StreamTokenizer已过时,最好使用Scanner,这是您的问题的示例代码:
String s = ".24 word -123"; Scanner fi = new Scanner(s); //anything other than alphanumberic characters, //comma, dot or negative sign is skipped fi.useDelimiter("[^\p{Alnum},\.-]"); while (true) { if (fi.hasNextInt()) System.out.println("Int: " + fi.nextInt()); else if (fi.hasNextDouble()) System.out.println("Double: " + fi.nextDouble()); else if (fi.hasNext()) System.out.println("word: " + fi.next()); else break; }
fi.useLocale(Locale.FRANCE);
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)