How to write one time header code in my prog ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • redcodeheaven
    New Member
    • Nov 2008
    • 13

    How to write one time header code in my prog ?

    Hi all,this program append records to a file,I like to know if ispossible to include a header something like " welcome to my program " but I need it one time to print on the file not everytime I add a record or when I login to my program,is it possible ?
    and what about searching inside the records fields ,does ArrayList is the best solution ? knowing that the toString() methods includes many fiels (name,last name,..etc )here is my code ,thanks everybody for any help....

    Code:
    public void writeToFile(String filename){
    			try {
    				String fileName = "myFile.txt";
    				BufferedWriter out = new BufferedWriter(new FileWriter(fileName, true));
     
     
    				out.write(toString() + "\n"); 
    				out.flush();
     
    				 out.newLine();
    				out.close();
    			}
    			catch (Exception e) {
    				System.out.println("IOException:");
    				e.printStackTrace();
    			}
    		}
    	}
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Before opening (and appending to) the file check if the file exists; if so it most likely already has a header written to it. Read the API documentation for the File class.

    kind regards,

    Jos

    Comment

    Working...