Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problems with encoding and files

 
Mercurio Savedra
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends pls some help my problems is the following

I have a ftp server running on linux and in my program I download files from the ftp server using class specified below.When I download the file content not all content is coming ok. For example I have a string with
Ra�l����1234%#=?[a_@ and when I read content using my methods this part is retirved ok Ra and this one is retrived wrong �����
whith characteres very stranges.

I suppose that the problem is with the encoding, then all day I tried some settings in the class new InputStreamReader.First the encoding UTF-8 because I have created the file using this encoding. Something like this:

in = new InputStreamReader(new GZIPInputStream(localFtp.get(serverFile)),"UTF-8");

but does not work

After I realized that I use the statement localFtp.ascii();
declaring that the content will be downloaded in ascii encoding so
I made this change :

in = new InputStreamReader(new GZIPInputStream(localFtp.get(serverFile)),"US-ASCII");

but still does not work

Please somebody can help me this is very urgent

Here is my code

Tkx

 
Mercurio Savedra
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I forgot this





Tkx
 
Alonso Faust
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To make sure I understand your problem correctly:
Your string should be received as: "Ra�l����1234%#=?[a_@"
Your string is received as Ra+jibber
Correct?
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Surely, if you've downloaded a non-ASCII file using ASCII encoding, you've already broken it. So it doesn't matter what encoding you use for reading after downloading it - you may be unable to fix it, because information may have been lost/corrupted. Trying to use "US-ASCII" for reading is never going to give good values for non-ASCII characters.

Shouldn't you download the file in binary?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic