我已经看过“类似”的问题,但无法得到我的答案。 如果已经存在,请指出一个。
问题:将String / StringBuilder保存为HTML格式时,它在页面的开头添加了其他字符,但我不知道为什么。 例:
’tX
方法:
public void saveToHTML(){
String fileName = "";
if (docName != null){
fileName += docName;
} else {
fileName += stdFileName;
}
fileName += "HTML.html";
String tempText = new String("\n\n\t
");int tabCount = 3;
for (int oneSec = 0; oneSec < allSections.size(); oneSec++){
for (int onePar = 0; onePar < allSections.get(oneSec).getCountParagraphs(); onePar++){
tempText += (convertParToHTML(allSections.get(oneSec).getParagraph(onePar),
tabCount));
}
}
tempText += ("\n\t\n");
serializeDoc(fileName, tempText.toString());
}
下面的serializeDoc():
/**
* Helper method to serialize files
*
* @param fileName name of the file to be saved with
* @param object object to be saved in the file
* @throws IOException
*/
private void serializeDoc(String fileName, Object object){
try {
FileOutputStream file = new FileOutputStream(fileName);
ObjectOutputStream out = new ObjectOutputStream(file);
out.writeObject(object);
out.close();
} catch (IOException e){
System.out.println("The file couldn't be created");
}
}