请帮我做这样的事情,让我们说我们有一个文本文件,的test.txt,大约与此类似:从文件读取?
hello hello hello
<link1>http://stackoverflow.com<link1>
文本的第一行,并封闭在第二个链接<link1>
。我打印文件的内容如下:
if(myName.equals(name)){
InputStreamReader reader = null;
try{
File file = new File("C:\\Users\\ваня\\Desktop\\asksearch\\" + list[i]);
reader = new InputStreamReader(new FileInputStream(file), "UTF-8");
int b;
PrintWriter wr = response.getWriter();
wr.print("<html>");
wr.print("<head>");
wr.print("<title>HelloWorld</title>");
wr.print("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">");
wr.print("<body>");
wr.write("<div>");
while((b = reader.read()) != -1) {
wr.write((char) b);
}
wr.write("</div>");
wr.write("<hr>");
wr.print("</body>");
wr.print("</html>");
wr.close();
}
只是一段代码:
while((b = reader.read()) != -1) {
writer.write((char) b);
}
要显示,文件本身的第一行,并在第二行文件分开
PrintWriter writer = response.getWriter();
writer.print("<html>");
writer.print("<head>");
writer.print("<title>HelloWorld</title>");
writer.print("<body>");
writer.write("<div>");
// then the first line
writer.write("</div>");
writer.write("<div>");
// then the second line
writer.write("</div>");
writer.print("</body>");
writer.print("</html>");
这就是所谓的“编程”你存储线字符串,另一个在另一个字符串。为了分隔行,最好使用'BufferedReader',它提供'readLine'方法。 – SJuan76
你能展示一段代码吗 –
是的你是对的我需要分开第一和第二行 –