真的很容易“新行”java问题

时间:2010-12-08 17:26:10

标签: java

非常简单的问题:

我正在尝试在此代码的下一行打印出时间戳。它正在打印到jTextArea。我现在如何获得代码由于某种原因不起作用:

try {
        Calendar calendar = Calendar.getInstance();
        Timestamp currentTimestamp = new     java.sql.Timestamp(calendar.getTime().getTime());

        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = factory.newDocumentBuilder();
        Document doc = docBuilder.newDocument();
        Element root = doc.createElement("message");
        doc.appendChild(root);
        root.appendChild(doc.createTextNode(userName.getText() + ": " + msgText.getText() + "\n" + "sent at " + currentTimestamp));
        TransformerFactory fact = TransformerFactory.newInstance();
        Transformer trans = fact.newTransformer();
        DOMSource source = new DOMSource(doc);
        StreamResult sResult = new StreamResult(out);
        trans.transform(source, sResult);
        msgText.setText("");
        out.println("\n");
        out.flush();
    } catch (Exception e) {

    }

...谢谢

1 个答案:

答案 0 :(得分:0)

GUYS你是对的,这是创建转换为XML的文档。我想在将xml再次转换为字符串后,我只会在另一边添加时间戳