How can i convert a file in ASCii/Dos format to ASCii/Unix format in Java ?

I write an application that takes file urls and charset names and than converts them into specified charset.
How can i make the conversion between ASCII/Dos -> ASCII/Unix et vice versa.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.

are you looking for tools? on unix / linux you can use commands like unix2dos and dos2unix
kodcanavariAuthor Commented:
No , i wanna code it. If would be good if i can pass charset type to the stream but i don't know if there is a charset encoding for ascii/ unix in java. Does anyone knows?
You can use iconv.
iconv --from-code=ISO-8859-1 --to-code=UTF-8 myfile > newfile

Open in new window

kodcanavariAuthor Commented:
thanks daniok, i've leared about iconv tool by this occasion but i really ned a java solution.
I have already converted other types of charset like ascii -> epcdic with the code below but i don't know how to do the same between ascii/dos and ascii/windows.
         File fichierSource = new File(p_UrlFichierSource);
         FileInputStream streamFichierSource = new FileInputStream(fichierSource);
         Reader readerStreamFichierSource = new InputStreamReader(streamFichierSource, "ASCII");
         BufferedReader bReader = new BufferedReader(readerStreamFichierSource);
         File fichierDestination = new File(p_UrlFichierDestination);
         FileOutputStream streamFichierDestination = new FileOutputStream(fichierDestination);
         Writer writerStreamFichierDestination = new OutputStreamWriter(streamFichierDestination, "CP500");
         BufferedWriter bWriter = new BufferedWriter(writerStreamFichierDestination);
         int ch;
         while ((ch = > -1) 
            bWriter.write((char) ch);
      catch (Exception e) 

Open in new window

Maybe you can substitute all Windows Carriage-Return (ASCII 13) with Unix Line Feed (ASCII 10) or viceversa. Or better  you can give a try to CRLF Class at


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

From novice to tech pro — start learning today.