txt文件数据转换为html文本

Newbie here on javascript and CSS, and I wanna know if it's possible to extract data from a .txt file and transform it to text and print on the page.
I was searching through some old topics, and did find some similiar questions, and I tried to copy but didn't work hahha
Here it is what I did try:

HTML:

<div id="printed"></div>

Script:

var text_print = new XMLHttpRequest();
        text_print.open("GET", "folder/file.txt", true);
        text_print.send();
        text_print.onload = function (){
            console.log( text_print.responseText.slice(0, text_print.responseText.indexOf("
")) ); };

    document.getElementById("printed").innerHTML=text_print;

The .txt file has only one line of text, btw.
Thank you.

The right answer depends on what you're trying to do.

If you just want to to display the text (and that's it)

you can use the embed tool

<embed src="test.txt">

Where 'test.txt' is the name of your text file.

Note that you also need the path of the text file. So if test.txt is in the file directory below, you should use

<embed src="../test.txt">

or

<embed src="folder/file.txt"

in your case.

This is very simple to type. The disadvantage to this is that (as far as I'm aware) there is no way to apply styling to the text that gets displayed.