Advertisement
guindous

Unix2Dos.java

Feb 22nd, 2013
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.87 KB | None | 0 0
  1. import java.io.*;
  2. // ---------------------------------------------------------------------------------
  3. // Formatos:
  4. //
  5. // Unix 10 'NewLine'
  6. // DOS  13 10 'Carriage Return' 'NewLine'
  7. // ---------------------------------------------------------------------------------
  8.  
  9. public class Unix2Dos {
  10.     public static void convierte(String origen, String destino) {
  11.         InputStream  is;
  12.         OutputStream os;
  13.         int charTmp;
  14.  
  15.         try {
  16.             is = new FileInputStream(origen);
  17.             os = new FileOutputStream(destino);
  18.  
  19.             charTmp = is.read();
  20.  
  21.             //Recorre el input stream, reemplazando CR por CR+LF
  22.             while (charTmp != -1) {
  23.                 //Si es un CR, escribe un LF
  24.                 if (charTmp == 10)
  25.                     os.write((int)13);
  26.  
  27.                 os.write(charTmp);
  28.  
  29.  
  30.                 //Lee el siguiente caracter...
  31.                 charTmp = is.read();
  32.             }
  33.  
  34.             os.flush();
  35.             os.close();
  36.             is.close();
  37.         }
  38.         catch(Exception e) {
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement