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.

Regards.
LVL 1
kodcanavariAsked:
Who is Participating?
 
dainokConnect With a Mentor Commented:
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 http://tanmaykm.tripod.com/work/javawork.html.

0
 
omarfaridCommented:
are you looking for tools? on unix / linux you can use commands like unix2dos and dos2unix
0
 
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?
0
 
dainokCommented:
You can use iconv.
iconv --from-code=ISO-8859-1 --to-code=UTF-8 myfile > newfile

Open in new window

0
 
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.
      try 
      {
         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 = bReader.read()) > -1) 
         {
            bWriter.write((char) ch);
         }
         
         bReader.close();
         bWriter.close();
 
      } 
      catch (Exception e) 
      {
         e.printStackTrace();
      }

Open in new window

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

All Courses

From novice to tech pro — start learning today.