• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 221
  • Last Modified:

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.
0
PCMENIAC
Asked:
PCMENIAC
  • 10
  • 4
  • 2
1 Solution
 
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 10
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now