Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.FileWriter;
- import java.io.IOException;
- public class EscribirArchivo {
- File archivo;
- private void crearArchivoDeTexto() {
- archivo = new File("archivo.txt");
- }
- private void escribirArchivo(String numeros) {
- try {
- FileWriter escritura = new FileWriter(archivo);
- escritura.write(numeros, 0, numeros.length());
- escritura.close();
- System.out.println("Archivo escrito con éxito");
- }catch(IOException e) {
- e.printStackTrace(System.out);
- }
- }
- private static String generarNumeros() {
- String numeros = "";
- int aux;
- for(int i = 1; i<5000;i++) {
- aux = Helper.random.nextInt(1,9999);
- numeros += aux+" ";
- }
- return numeros;
- }
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- EscribirArchivo archivo = new EscribirArchivo();
- String contenido = generarNumeros();
- archivo.crearArchivoDeTexto();
- archivo.escribirArchivo(contenido);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement