Special Characters in the file downloaded from a FTP site

Hi There,

Just wondering, can anybody tell me whether we get the special character(s) at the end of every line when downloading a CSV File from the FTP SITE.

I know this is the case when downloading a text file from a FTP site.

Thanks for clarifying!!

Regards.
PCMENIACAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
You should download in ascii mode
0
objectsCommented:
If you download the file in binary mode, then the recieved file will be identical to the one on the server.
0
objectsCommented:
> I know this is the case when downloading a text file from a FTP site.

if using text mode, then the same will apply for the csv file as does with a text file
ie. a csv file is a text file.
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

CEHJCommented:
(The default mode is usually binary, which won't convert line breaks for your platform properly)
0
objectsCommented:
> (The default mode is usually binary, which won't convert line breaks for your platform properly)

Already mentioned
0
CEHJCommented:
>>Already mentioned

ROTFL. You must have a special view of this question that nobody else has - or certainly not me ;-)
0
objectsCommented:
> If you download the file in binary mode, then the recieved file will be identical to the one on the server.
0
CEHJCommented:
LOL - and you think those comments are the same do you !?
0
PCMENIACAuthor Commented:
I'm sorry guys but I still don't get it!! This is the java code that I'm using for geting the file from the FTP site:

********************************************************************************************
URL url = new URL(logonDetails + serverDetails + fileName);
InputStream in = url.openStream();
File newFile = new File(fileName);
FileOutputStream out = new FileOutputStream(newFile);
           
final int bufferSize = 8192;
byte[] buffer = new byte[bufferSize];
int bytesRead = -1;
int nread = 0;
           
while((bytesRead = in.read(buffer)) >-1)
{
  nread += bytesRead;
  out.write(buffer, 0, bytesRead);
}
in.close();
out.close();

I think this download the file in ASCII mode, does it??

Thanks,
Parag
0
CEHJCommented:
No, use Readers to do it, not InputStreams
0
CEHJCommented:
You're currently using binary mode. Do this:

String buffer = null;
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
while((buffer = in.readLine() != null)
{
      // write buffer to file
}


0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CEHJCommented:
>>while((buffer = in.readLine() != null)

should have been

while((buffer = in.readLine()) != null)
0
PCMENIACAuthor Commented:
Thanks CEHJ,

I'll give it a try and let you guys now. I've found out that the when I connect to the FTP Site, its opening an ASCII mode data transfer. Also the files that need to be downloaded are being generated by using a new line character.

Does that effect the way I download the files??

Parag
0
CEHJCommented:
>>I've found out that the when I connect to the FTP Site, its opening an ASCII mode data transfer

That's unlikely, otherwise you wouldn't have a problem with line breaks.

>>Also the files that need to be downloaded are being generated by using a new line character

I assume you mean *just* a newline character ('\n'). That's fine if the receiving platform is a Unix one. Otherwise it will give you the wrong line breaks
0
CEHJCommented:
>>Otherwise it will give you the wrong line breaks

But with the code i gave you last, the line breaks will be automatically converted for the receiving platform
0
CEHJCommented:
8-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.