n (new line) not working in creating text file

I want to download the text file by clicking on button, everything is working fine as expected. But the problem is the data I want to insert in text file is just one line.

String fileContent = “Simple Solution nDownload Example 1”; here, n is not working. It resulting in output as:

Simple Solution Download Example 1

Code snippets:


enter image description here

interface implementation in my service class:

enter image description here


enter image description here


Don’t use hardcoded n nor rn – line-separators are platform-specific (Windows differs to all other OS).

What you can do is:

  1. Use System.lineSeparator()
  2. Build content with String.format() and replace n with %n