0
這裏的前導空格是我的輸出:「四個分值87年前......」我的令牌似乎跳過一個文本文件
但是,預期的輸入是:「四個分值七年前......「(帶引號和‘四’之間的空間」。
我如何保持領先的空白?這裏是我到目前爲止的代碼。
public void checkDocument(Reader in, InputStream input, Writer out) throws IOException {
Scanner sc = new Scanner(input);
TokenScanner tok=new TokenScanner(in);
Token too;
Set<String> fileCor=new HashSet<String>();
while (tok.hasNext()){
too=tok.next();
System.out.println(too);
if (too.isWord()){
if (!(dict.isWord(too.toString()))){
int n=1;
fileCor=corr.getCorrections(too.toString());
List<String> sortedOptions=new LinkedList<String>(fileCor);
Collections.sort(sortedOptions);
System.out.println("The word: "+too.toString()+" is not in the dictionary. Please enter the number corresponding with the appropriate action:");
System.out.println("0: Ignore and continue");
System.out.println("1: Replace with another word");
for (int i=0;i<sortedOptions.size();i++){
n=n+i+1;
System.out.println((i+2)+": Replace with \""+sortedOptions.get(i)+"\"");
}
int choice=getNextInt(0, n, sc);
if (choice==0){
}
else if (choice==1){
out.write(getNextString(sc).trim());
}
else out.write(sortedOptions.get(choice-2).trim());
}
else out.write(too.toString().trim());
}
else {
out.write(too.toString());
}
}
System.out.println("Document completed");
}
}
[Trim()](http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#trim())返回字符串的副本,省略了前導和尾隨的空白。可能是這個問題。 – RanRag 2012-04-12 02:47:52