Problem with encoding and charset for downloading a file
Melssj5May 22 2013 — edited May 22 2013Hi guys, I have a problem and I beg for your help, I am 1000% frustrated at this point.
I have a servlet which have to do something and give a file log to the final user. Coding the logic for that took me about 5 minutes, the problem is that the given file doesnt shows properly in notepad (Default app to open txt files). I have tried every way I have read over the internet and absolutely nothing works.
After trying about 20 different ways fo doing this without success, this is my actual code:
Charset def=Charset.defaultCharset();
OutputStreamWriter out = new OutputStreamWriter(servletOutputStream,def);
for (String registry:regList) {
out.write(registry+"\n");
}
out.close();
the page gives the file to the user, I can download or open it, when I open it this is the result
registry1registry2registry3registry4registry5registry6registry7...
and I am expecting:
registry1
registry2
registry3
registry4
registry5
.
.
.
If I open it with wordpad or notepad++ the file looks fine, but I cant achieve that notepad reads it correctly. I have spent about 10 hours on this and at this point I just dont know what to do, i have tried Windows-1252, UTF-8, UTF-16, the Default one. I have tried to set this enconding on the response header with no luck. Any help will be very appreciated.
Thanks in advance.