我们需要从下到上逐行读取文件的情况,代码如下:
StringBuilder sb = new StringBuilder("<html><body>");
sb.append("<p>A list of messages are:</p>");
for(String str : listMessages){
sb.append("Message: ").append(str).append("<br/>");
}
sb.append("</body></html>");
FacesMessage message = new FacesMessage(sb.toString());
message.setSeverity(FacesMessage.SEVERITY_INFO);
FacesContext.getCurrentInstance().addMessage("", message);
以上代码适用于ASCII,但对于utf-8编码文件,内容混乱且无法读取。
答案 0 :(得分:0)
var filename = "file.txt";
var lines = System.IO.File.ReadAllLines(filename, Encoding.UTF8).Select(line => new string(line.Reverse().ToArray())).Reverse().ToList();
对于Enumerable,它应该是
var lines = System.IO.File.ReadLines(filename, Encoding.UTF).Reverse().Select(x => new string(x.Reverse().ToArray()));