File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Problems with encoding and files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Problems with encoding and files" Watch "Problems with encoding and files" New topic

Problems with encoding and files

Mercurio Savedra

Joined: Dec 04, 2005
Posts: 25
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


Mercurio Savedra

Joined: Dec 04, 2005
Posts: 25
I forgot this

Alonso Faust

Joined: Dec 19, 2007
Posts: 14
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

"It is but the bedazzlement of the Great Enchanter which makes the Terrible Giants appear as windmills, to the untrained eye."
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
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?

Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
I agree. Here's the link:
subject: Problems with encoding and files
It's not a secret anymore!