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/>");
精彩评论