开发者

How to display a CSV file string as HTML with line-break tags?

I have a CSV file stored in my databa开发者_Python百科se as a blob.

My API only allows me to return it as a single String - I would have preferred a List of Strings representing each line of the file.

String fileText = new String(blobDb.fetchData(key, 0, fileLength));

Rather than display the file as an unending block of text:

<html>
    <head>
        <title>File Contents:</title>
</head>
<body>

${fileText}

</body>
</html>

Is it possible to somehow break it up into separate lines of HTML broken up by <br/> tags?


Either use the HTML <pre> element

<pre>${fileText}</pre>

or apply CSS white-space: pre; on the containing element

<div style="white-space: pre;">${fileText}</div>


fileText = fileText.replaceAll("\n", "<br/>");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜