Visualizzazione dei risultati da 1 a 2 su 2

Discussione: [java] append file

  1. #1
    Utente di HTML.it
    Registrato dal
    Feb 2004
    Messaggi
    724

    [java] append file

    ho creato questa funzione per salvare su di un file dei dati. Esiste un metodo per eseguire un append in fondo al file per poter salvare dati di sessioni di lavoro diverse??

    codice:
    public boolean salva(){
    try{
    ObjectOutputStream out=new ObjectOutputStream(new FileOutputStream("pag.txt"));
    out.writeObject(el.toString());
    out.close();
    }catch(Exception e){return false;}
    return true;}

  2. #2
    Utente di HTML.it L'avatar di Angelo1974
    Registrato dal
    Feb 2003
    Messaggi
    1,107
    Ciao semplicemente dovresti fare:


    Codice PHP:
    public boolean salva(){
    try{
    ObjectOutputStream out=new ObjectOutputStream(new FileOutputStream("pag.txt"true));
    out.writeObject(el.toString());
    out.close();
    }catch(
    Exception e){return false;}
    return 
    true;} 
    Mettendo true setti in modalità append il FileOutpuStream:

    Codice PHP:
    public FileOutputStream(File file,
                            
    boolean append)
                     
    throws FileNotFoundExceptionCreates a file output stream to write to the file represented by the specified File object. If the second argument is truethen bytes will be written to the end of the file rather than the beginningnew FileDescriptor object is created to represent this file connection
    First, if there is a security managerits checkWrite method is called with the path represented by the file argument as its argument

    If 
    the file exists but is a directory rather than a regular filedoes not exist but cannot be created, or cannot be opened for any other reason then a FileNotFoundException is thrown


    Parameters:
    file the file to be opened for writing.
    append - if truethen bytes will be written to the end of the file rather than the beginning 
    Throws

    FileNotFoundException - if the file exists but is a directory rather than a regular filedoes not exist but cannot be created, or cannot be opened for any other reason 
    SecurityException 
    - if a security manager exists and its checkWrite method denies write access to the file.
    Since
    1.4 
    Ciao
    Se vuoi trovare l'arcobaleno, devi sopportare la pioggia

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.