Ver Mensaje Individual
  #4 (permalink)  
Antiguo 02/07/2008, 15:04
maiden17
 
Fecha de Ingreso: junio-2008
Ubicación: Cali, Colombia
Mensajes: 74
Antigüedad: 15 años, 10 meses
Puntos: 3
Respuesta: escribir en un txt

Hola, intenta esto, ya es que tu le hagas las modificaciones correspondientes a la ruta de guardado del archivo.

Código:
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * 
 */
public class Seccion {
    static FileWriter archivo = null;
    public static BufferedWriter bw;
    public static void main (String args[]) {
    String ruta = "/home/juan/Alumnos.txt";
    abrir (ruta);

    /* Pedir la vantida de estudiantes
    transformar esa entrada en interero
    asignar a n = 5 */
    /* Hacer el llamafa a las clases de lectura
    * y escritura */
    Estudiante estudiantes [] = new Estudiante [5];

    double notaest0[]={-8,9.08,13.7,10.0};
    estudiantes[0] = new Estudiante ("Patricia",15147258,notaest0);
    if (bw!=null){
        escribir(estudiantes);
        //escribir(estudiantes[0]);
        vaciarBuffer();
    }
    double notaest1[]={18.9,15.08,13.9,08.0};
    estudiantes[1] = new Estudiante ("Williams",16000879,notaest1);
    if (bw!=null){
        escribir(estudiantes);
        vaciarBuffer();
    }
    double notaest2[]={15.8,19.08,12.9,05.0};
    estudiantes[2] = new Estudiante ("Ines",17007521,notaest2);
    if (bw!=null){
        escribir(estudiantes);
        vaciarBuffer();
    }
    double notaest3[]={15.8,16.08,11.1,04.9};
    estudiantes[3] = new Estudiante ("Cesar",23258147,notaest3);
    if (bw!=null){
        escribir(estudiantes);
        vaciarBuffer();
    }
    double notaest4[]={20.0,16.08,15.1,18.9};
    estudiantes[4] = new Estudiante ("Luis",24123456,notaest4);
    if (bw!=null){
        escribir(estudiantes);
        vaciarBuffer();
    }

    // Nombre del estudiante con el promedio mas alto
    cerrar();

    Estudiante mejor = estudiantes[0];
    for (int i=1; i<estudiantes.length; i++) {
        if (mejor.getPromedio()<estudiantes[i].getPromedio())
            mejor = estudiantes[i];
    }

    System.out.println("El promedio mas alto lo tiene: "+mejor.getNombre());

    // Cedula del estudiante con la calificacion mas baja

    Estudiante peor = estudiantes[0];
    for (int i=1; i<estudiantes.length; i++) {
        if (peor.getCalificacionMasBaja()>estudiantes[i].getCalificacionMasBaja())
            peor = estudiantes[i];
    }

    System.out.println("La cedula del estudiante con la peor nota es: "+peor.getCedula() + "con nota: "+peor.getCalificacionMasBaja());

    }
    public static void abrir (String ruta){
        try{
            archivo = new FileWriter (ruta);
            bw = new BufferedWriter (archivo);
        }
        catch (IOException e){
            bw = null;
        }
    }

    public static void escribir (Estudiante estudiante []){
        try {
            for(int i=0; i<estudiante.length; i++)
            bw.write(""+estudiante[i]);
            bw.newLine();
        }
        catch (IOException e){
            System.out.println("Error de escritura en el archivo");
        }
    }

    public static void vaciarBuffer(){
        try{
            bw.flush();
        }
        catch (IOException e){
            System.out.println("Error vaciando el Buffer");
        }
    }

    public static void cerrar (){
        try{
            archivo.close();
        } 
        catch (IOException e){
            System.out.println("Error cerrando el archivo");
        }
    }
}
Pruebalo y me dices

Saludos