
Convertir un archivo de texto cada palabra en una nueva línea
Publicado por Albert (13 intervenciones) el 15/05/2017 09:15:41
Básicamente mi proposito es convertir un archivo de texto que contiene texto en un archivo donde cada palabra este en una línea, tengo la mayor parte del codigo hecho pero estoy atascado en la parte de hacerle dar el salto de linea a las palabras del archivo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import java.io.*;
import java.util.StringTokenizer;
public class conversorArchivo{
public static void main(String[] args) {
String prueba = "Hello World, today i'm trying to do the best";
Salida(prueba);
Entrada();
}
public static void Salida(String prueba){
DataOutputStream salida;
try{
FileWriter fw = new FileWriter("D:/DAM/Programacion/archivo.txt");
PrintWriter pw = new PrintWriter(fw);
salida = new DataOutputStream(new FileOutputStream("D:/DAM/Programacion/archivo.txt"));
sortida.writeUTF(prueba);
sortida.close();
}catch(IOException e){
System.out.println("Excepcion: "+e.getMessage());
}
}
public static void Entrada(){
try {
DataInputStream entrada;
entrada = new DataInputStream(new FileInputStream("D:/DAM/Programacion/archivo.txt"));
StringTokenizer st = new StringTokenizer(entrada.readUTF()," ");
while(st.hasMoreTokens()){
System.out.println(st.nextToken());
}
}catch(IOException e){
System.out.println("\nExcepcion: "+e.getMessage());
}
}
}
Valora esta pregunta


0