我正在做的是我正在阅读一个 html 文件,并且我正在寻找 html 中的特定位置供我输入一些文本。所以我使用缓冲阅读器读取 html 文件并按标签拆分它。我想在此之前输入一些文本,但我不知道该怎么做。然后 html 将沿着 ...(newText)(/HEAD) 的行(括号圆头是尖括号。不知道如何插入它们)
我是否需要一个 PrintWriter 到同一个文件,如果是这样,我将如何告诉它把它写在正确的位置。我不确定哪种方式最有效地做这样的事情。请帮忙。
提前致谢。
这是我的java代码的一部分:
File f = new File("newFile.html");
FileOutputStream fos = new FileOutputStream(f);
PrintWriter pw = new PrintWriter(fos);
BufferedReader read = new BufferedReader(new FileReader("file.html"));
String str;
int i=0;
boolean found = false;
while((str= read.readLine()) != null)
{
String[] data = str.split("</HEAD>");
if(found == false)
{
pw.write(data[0]);
System.out.println(data[0]);
pw.write("</script>");
found = true;
}
if(i < 1)
{
pw.write(data[1]);
System.out.println(data[1]);
i++;
}
pw.write(str);
System.out.println(str);
}
}
catch (Exception e) {
e.printStackTrace( );
}
当我这样做时,它会到达文件中的某个点,并且出现以下错误:
致命错误:MERLIN:无法连接到 EDG API,
找不到 .edg_properties 文件。,
java.lang.OutOfMemoryError:无法创建新的本地线程,
无法截断表,
例外:无法打开与服务器的连接:SQLExceptio,
捕获 IOException: java.io.IOException: JZ0C0: Connection is already closed, ...
我不知道为什么我会得到这些或所有这些是什么意思?
请帮忙。