java字符串转html对象吗,java - 当Java中的String转换为HTML文件时,为什么还会出现其他字符? - 堆栈内存溢出...

我已经看过“类似”的问题,但无法得到我的答案。 如果已经存在,请指出一个。

问题:将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");

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值