<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">import java.io.*;

public class EscribeFichero {
   public static void main(String[] args) {
      FileWriter fichero = null;
      PrintWriter pw = null;
      try {
         fichero = new FileWriter("./prueba.txt");
         pw = new PrintWriter(fichero);

         for (int i = 0; i &lt; 10; i++)
            pw.println("Linea " + i);

      } catch (Exception e) {
         e.printStackTrace();
      } finally {
         try {
            // Nuevamente aprovechamos el finally para
            // asegurarnos que se cierra el fichero.
            if (null != fichero)
               fichero.close();
         } catch (Exception e2) {
            e2.printStackTrace();
         }
      }
   }
}

</pre></body></html>