473,478 Members | 2,028 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to write one time header code in my prog ?

13 New Member
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....

Expand|Select|Wrap|Line Numbers
  1. public void writeToFile(String filename){
  2.             try {
  3.                 String fileName = "myFile.txt";
  4.                 BufferedWriter out = new BufferedWriter(new FileWriter(fileName, true));
  5.  
  6.  
  7.                 out.write(toString() + "\n"); 
  8.                 out.flush();
  9.  
  10.                  out.newLine();
  11.                 out.close();
  12.             }
  13.             catch (Exception e) {
  14.                 System.out.println("IOException:");
  15.                 e.printStackTrace();
  16.             }
  17.         }
  18.     }
  19.  
  20.  
Apr 10 '09 #1
1 1526
JosAH
11,448 Recognized Expert MVP
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
Apr 11 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
5687
by: Werner Merkl | last post by:
Hi, Python is really great, for small to big programs. For my colleagues and some circumstances I sometimes need to "compile" a script using py2exe. Cause I use Windows, I like to use the...
6
8748
by: haynesc | last post by:
Hi, I'm having a problem where when trying to open a file in write mode, I get an IOError stating no such file or directory. I'm calling an external program which takes an input file and...
6
2457
by: Jofio | last post by:
I have a .h (header file) linked using #include<...>. I also have a .cp file which i don't know how to include in the header of my "main" file. I have the following c++ file. The file names are:...
9
1930
by: davide.sammartino | last post by:
Hi, when the processor meet this instruction i >4; the operation, inside the processor, is computed constantly or linearly in time?
0
3540
by: DC | last post by:
The problem I'm using the .NET GridView and FormView objects for the first time and im getting the error "An OleDbParameter with ParameterName '@ID' is not contained by this...
4
5628
by: childtobe | last post by:
I want to write the time to a file. (to implement this in an other piece of code that i've writen) For some reason he gives me a C2064 error when i try to put the time into a string. As you can...
10
7610
by: sheilly_2k7 | last post by:
how can i write an output of a c prog in a file in plce of terminal witout using redirection
3
1483
by: iovecpsc | last post by:
Say I wanted to create a header file for my program. Would the variables in the header be defined globally for the file that it is attached to. //header.h //#ifndef HEADER_EXAMPLE //#define...
2
1714
by: Bubbs | last post by:
hi, Lemme give u a little background on my problem. Ive created a client and server applications that receive and stream live time values. The client software is a clock that receives the time and...
0
7027
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6899
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7019
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7067
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
6847
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5312
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4757
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
2970
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1288
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.