elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Como proteger una cartera - billetera de Bitcoin


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  Ejercicios
| | | |-+  transformar y cambiar las palabras de un archivo.txt con java
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: transformar y cambiar las palabras de un archivo.txt con java  (Leído 6,346 veces)
roby79

Desconectado Desconectado

Mensajes: 5


Ver Perfil
transformar y cambiar las palabras de un archivo.txt con java
« en: 11 Mayo 2012, 04:15 am »

hola!
¿Me podeis ayudar por favor?
Tengo un proyecto con java. el texto es el siguiente:
a partir de un archivo txt  imprimir el contenido de cada fila recibida.
Una vez que tenemos el archivo de texto, por cada palabra, más grande que tres letras, cambiamos la distribución de las letras, excepto la primera letra y la última letra.
ejemplo:

Imagine there's no heaven, it's easy if you try
No hell below us above us only sky.
Imagine all the people living for today...


transformar:

Iganime tehre's no hveean, it's esay if you try
No hlel bolew us avbove us olny sky.
Iimnage all the pelpoe lvniig for tdaoy...


Una vez que cambie las palabras entrar en otro archivo txt con la puntuacion misma.

Hasta ahora, he hecho esto (y no puedo ir por delante):
Código:

 package ejercicio;   
       
    import java.io.BufferedReader;   
    import java.io.File;   
    import java.io.FileReader;   
    import java.io.IOException;   
    import java.util.Random;   
    import java.util.StringTokenizer;   
       
    /** 
     * @author roby 
     */   
    public class Ejercicio {public static String mixpalablas(String inicio){         
               
            char[] vec1 = inicio.toCharArray();   
            char[] vec2 = inicio.toCharArray();   
               
            Random random = new Random();         
            int r = random.nextInt(vec1.length-1);   
            int i = 0;   
            int j = r+1;   
            while(i <= r){   
               vec2[vec1.length -i-1] = vec1[i];   
                i++;   
            }   
            while (j <= vec1.length -1){   
               vec2[j-r-1] = vec1[j];   
                j++;   
            }   
            String nuevapalabra = String.valueOf(vec2);   
            return nuevapalabra;   
    }   
       
        /** 
         * @param args the command line arguments 
         */   
        public static void main(String[] args) throws IOException {   
            String archivo = "r://ejercicio.txt";   
            String s = "";   
            String token="";   
            int count = 0;   
            int j = 0;   
            int f = 0;   
            int i = 0;   
            boolean t = true;   
            char hola;   
            String q=".,:;?!";   
            String nuevotexto="";   
            String mix="";   
            try {   
                File file = new File(archivo);   
       
                if (file.exists()) {   
                    System.out.println("Il file " + archivo + ": existe");   
                } else if (file.createNewFile()) {   
                    System.out.println("Il file " + archivo + ": ya esta creado");   
                } else {   
                    System.out.println("Il file " + archivo + " :no se puede crear");   
                }   
                System.out.println("");   
       
            } catch (IOException e) {   
                System.out.println("error en la creacion");   
            }   
            try {   
       
                System.out.println("el contenido del archivo es el siguiente: ");   
                System.out.println("");   
                BufferedReader leer = new BufferedReader(new FileReader(archivo));   
       
                while ((s = leer.readLine()) != null) {   
                    System.out.println(s);   
                }   
                leer.close();   
            } catch (IOException e) {   
                System.out.println("error bufferReader");}   
            try {   
                System.out.println("");   
                BufferedReader leer = new BufferedReader(new FileReader(archivo));   
       
                while ((s = leer.readLine()) != null) {   
                    count++;   
                    if (s.charAt(count)!=',')   
                      hola=s.charAt(count);     
                }   
                System.out.println("la lineas son " + count);   
                leer.close();   
            } catch (IOException e) {   
                System.out.println("error bufferReader");   
            }   
            try {   
                System.out.println("");   
                BufferedReader leer = new BufferedReader(new FileReader(archivo));   
                while ((s = leer.readLine()) != null) {   
                    f++;   
                    System.out.println("linea " + f + " = " + s.length() + " letras");   
                }   
                leer.close();   
            } catch (IOException e) {   
                System.out.println("error bufferReader2");   
            }   
            System.out.println("");   
            try {   
                BufferedReader leer = new BufferedReader(new FileReader(archivo));               
                while((s = leer.readLine())!= null){     
          StringTokenizer st = new StringTokenizer(s);     
          while (st.hasMoreTokens()) {   
                token=st.nextToken();     
                if(token.length()>3){   
             nuevotexto = token.replaceAll ("[ \\p{Punct}]", "");   
             mix=mixpalablas(nuevotexto) ;         
             System.out.println(mix);   
          }}}   
                leer.close();   
            } catch (IOException e) {   
                System.out.println("error bufferReader3");   
             }     
        }}   


En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines