Java:BufferedWriter.write()
De W3API
Contenido |
[editar] Descripción
Método que nos permite escribir contenido sobre un buffer de escritura.
[editar] Sintaxis
public void write(int c) throws IOException public void write(char[] cbuf, int off, int len) throws IOException public void write(String s, int off, int len) throws IOException
[editar] Parámetros
- c,
- cbuf,
- off,
- len,
- s,
[editar] Excepciones
[editar] Clases Java a las que aplica
[editar] Ejemplo
// Validamos si existe el fichero
String sFichero = "fichero.txt";
File fichero = new File(sFichero);
if (fichero.exists())
System.out.println("El fichero " + sFichero + " ya existe");
else {
try{
BufferedWriter bw = new BufferedWriter(new FileWriter(sFichero));
// Escribimos 10 filas
for (int x=0;x<10;x++)
bw.write("Fila numero " + x + "\n");
// Hay que cerrar el fichero
bw.close();
} catch (IOException ioe){
ioe.printStackTrace();
}
}