public void saveToTextFile(String outText) throws IOException
{
BufferedWriter out = new BufferedWriter(new FileWriter(outText));
String[] keys=new String[words.size()];
int[] values=new int[words.size()];
int i=0;
for(String word : words.keySet())
{
keys[i]=word;
values[i]=words.get(word);
i++;
if(i==words.size()) //Έχουμε διασχίσει όλο το HashMap
{
break;
}
}
bubbleSort(values,keys);
for(i=0;i<words.size();i++)
{
out.write(keys[i]);
out.write(",");
out.write(values[i]);
out.write("\n");
}
out.close();
}
我有上述功能,當我打開文件時,它會創建它像: 你好,你,是,好,怎麼樣,謝謝,太,世界,以及前兩個逗號後的一些奇怪的符號。這就像out.write(values [i]);和out.write(「\ n」);不工作!我檢查了bubbleSort *之後的數組,並且它們都很好!問題appers,應以書面文件...BufferedWriter.write()方法不寫整數文件
這是我得到的,whick是正確的:
Word: hello Frequency: 2
Word: you Frequency: 2
Word: are Frequency: 1
Word: fine Frequency: 1
Word: how Frequency: 1
Word: thanks Frequency: 1
Word: too Frequency: 1
Word: world Frequency: 1
1)沒有必要在標題中添加主標籤。 2)請不要忘記添加'?'提問!有些人在頁面中搜索'?'如果'問題'中不存在,則直接進入下一個(實際)問題。 –