import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.RandomAccessFile;
public class Jugadores {
public static void main(String[] args) throws IOException {
//declaramos objeto jugador
Jugadores jugador = new Jugadores();
//apertura del fichero
RandomAccessEjercicio Apertura = new RandomAccessEjercicio("C:\Users\FER\Downloads\jugadores.txt","rw");
//creamos el fichero
Apertura.crearFichero();
//declaramos el objeto
RandomAccessFile objeto2;
//conseguimos el objeto random a traves del metodo get object
objeto2=Apertura.getObj();
//escribimos el array
jugador.escribirArrayFichero(objeto2);
}
public void escribirArrayFichero(RandomAccessFile param) throws IOException {
String[] jugadores = {"jugador 1 ","jugador 2","jugador 3","jugador 4","jugador 5"};
String[] apellidos = {"Garcia","nuñez","Gomez","Nuñez","Rios"};
String[] equipo = {"Real Madrid","Atletic","Barcelona ","Betis","Sevilla"};
String[] posicion = {"central","lateral","delantero","portero","Extremo"};
int[] edad = {18,21,19,20,22};
int i = 0;
param.writeBytes("NOMBRE");
param.writeBytes("\r\n");
for(i=0;i<5;i++) {;
param.writeBytes("\r\n"+jugadores[i]);
}
param.writeBytes("\n\r");
param.writeBytes("\n"+"APELLIDOS");
for(i=0;i<5;i++) {;
param.writeBytes("\r\n"+apellidos[i]);
}
param.writeBytes("EQUIPO");
param.writeBytes("\r\n");
for(i=0;i<5;i++) {;
param.writeBytes("\r\n"+equipo[i]);
}
param.writeBytes("\n\r");
param.writeBytes("\n"+"APELLIDOS");
for(i=0;i<5;i++) {;
param.writeBytes("\r\n"+posicion[i]);
}
param.writeBytes("\n\r");
param.writeBytes("\n"+"EDAD");
for(i=0;i<5;i++) {;
param.writeBytes("\r\n"+edad[i]);
}
}
}
I do not write the fields correctly in the file, example:
NOMBRE APELLIDOS EQUIPO POSICION EDAD
x x x x x
x x x x x
x x x x x
x x x x x
x x x x x
I've tried it with the method seek
but I still write horizontally, I know it's a matrix and I should do an array of two positions but I do not know how to actually do it