• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

text file as Ascii & Binary file

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I need to get (copy) text file from remote location... I can get it as ascii (byte []) using enterprisedt library , is there any way to get text file as binary?
any suggestions please?

I tried to get same file as binary but when I opens it it shows binary data in notepad.

thanks & regards..
 
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so you may need to clarify your question a bit. A text file IS a binary file - it is just one that only uses a certain sub-set of ASCII characters (ok..that is a slight oversimplification, but it is more or less true).

So if you have a text file, what exactly do you mean by "get it as binary"? What are you missing with your current method that you hope to gain?
 
San Metro
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am sorry, - I am confused and lost bit..


I am getting file from remote as BufferedOutputStream using com.enterprisedt.net.ftp.ssl.SSLFTPClient.get(BufferedOutputStream, FileName).

I do get

SSLFTPClient.get()

Before I do get, I have 2 options to set, get as - ascii / binary

ascii - there is an issue and new line is not working on notepad (\CR is expected by notepad and since its not in byte stream, data continues on same line.)

binary - I thought to set binary before get, but notepad shows binary data when I pass it to web layer.. so I am trying to understand my mistake, how can I get text file as binary.


thanks..

 
Marshal
Posts: 79808
388
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Take no notice of what Notepad says. It is no good with line ends for a start.
If you really are getting a file as text, you can read each line with Scanner#nextLine or similar. You should find it will accept CR CRLF or LF as a line end, but look in the Scanner#nextLine documentation.
 
Marshal
Posts: 28305
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For most FTP clients, if you tell it to get a file using ASCII transfer then it will adjust the end-of-line characters to whatever the client's convention is. So for a Windows client, it should be returning CR/LF rather than CR for line endings.

However it appears that it isn't doing that. So that means you aren't telling the FTP client to do an ASCII transfer, and it's doing a binary transfer instead. Note that it has nothing to do with whether you use an InputStream or a Reader to get the data from the FTP client, it depends only on how you set up the transfer in the client.

And furthermore that implies that your attempted solution of doing a binary transfer is exactly the wrong thing to do. Just tell the FTP client to do an ASCII-mode transfer.
 
Bartender
Posts: 1051
5
Hibernate Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you tried

before you get the file?
 
Evil is afoot. But this tiny ad is just an ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic