gpt4 book ai didi

Java SE file.txt 转换为 file.html

转载 作者:行者123 更新时间:2023-12-01 10:49:39 25 4
gpt4 key购买 nike

如何将file.txt的所有单词转换为html?

public class Main {

private static String name = "writer.html";
private static String Text = "C://Users//Vladimir//IdeaProjects//Algorithms//src//pack/textfile.txt";

public static String readtxt(String filename) throws IOException{

BufferedReader reader = new BufferedReader(new FileReader(filename));
String s;
StringBuilder sb = new StringBuilder();

while((s = reader.readLine()) != null) {
sb.append(s + "\n");
}

reader.close();
return sb.toString();
}

public static Object writer(String fileName,String text){
Text = text;
try {
PrintWriter out = new PrintWriter(new File(fileName));
try {
out.print(Text);
} finally {
out.close();
}
} catch (IOException e) {
throw new RuntimeException(e);
}
return null;
}
}

writer.html(输出 - C://Users//Vladimir//IdeaProjects//Algorithms//src//pack/textfile.txt)

最佳答案

首先改变这个,

来自 -

sb.append(s + "\n");

至 -

sb.append(s + "<br/>");

同时删除这个,

Text = text; // not needed

在这里改一下,

out.print(text);

我认为它应该可以按照您的要求正常工作。

关于Java SE file.txt 转换为 file.html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33986360/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com