我有一个日志文本文件,由若干个标签,如下列:解析文本文件标记为XML - Java的
<log level="info" id="12144" ....> <msg> test msg </msg> </log>
我要分析此文件,因此我认为,因为它看起来像XML我可以将xml(<?xml version="1.0"?
>)和一个根(<file>
)标记添加到文件中,然后使用DOM解析器对其进行解析。
但目前,我面临的问题是在文件的开头添加文本,因为所有可用的选项都要覆盖,或者将原始文件复制到临时位置,然后添加目标文本适用于我,因为我正在处理大于100 MB的文件。
I use the below code to try to add the text at the beginning, and I tried several solutions or classes other than RandomAccessFile
RandomAccessFile RAF = new RandomAccessFile(file, "rw");
RAF.getChannel().position(0);
RAF.write(("<?xml version=\"1.0\" encoding=\"UTF-8\"?> \r\n <file> \r\n").getBytes());
RAF.close();
您是否有任何建议在开始时添加文本或解析文本文件,并提取元素?
感谢,
显示您的代码。 – VHS