473,385 Members | 1,645 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

[Q] Deleting records in flat files

Dear Readers,

I am developing an application that stores "messages" in array list
and writes new entries to a disk file at the end. This file is used
incase the user choses to restart the program. When the program is
restarted the messages are replayed so the application knows where it
is up to.

I am not allowed to use a **database** I have been instructed to use a
flat file. The application I am replacing does that.

Everything works fine until someone wants to delete a message from the
list. In the Arraylist I simply remove the entry. Which is easy.

However for the file I re-create (delete and re-create) the entire
file with the new records - which seems a waste and exposes possible
danger if the users shuts the application down while re- creating the
file. I know this is small, but I would like to remove all risks.

I am writing the file as binary file stream, with a "message" length
followed by the variable length messages.

Is there any way I can deleted records in the centre of the file
without recreating the file?

Failing deleting the records is there a way I could rewrite a record
in the current file to indicate it should not be reloaded on restart.
I have plenty of space free in the records for some flag.

I know that a database is a better way to do this however I have been
told not to use a database.

Any suggestions.

Stuart
Nov 16 '05 #1
2 1827
Why don't you simply rewrite the date in a *new* file, and after everything
has been written, delete the old file and rename the new file with the name
of the original file.

--
cody

Freeware Tools, Games and Humour
http://www.deutronium.de.vu || http://www.deutronium.tk
"Stuart Norris" <st**********@yahoo.com.au> schrieb im Newsbeitrag
news:51**************************@posting.google.c om...
Dear Readers,

I am developing an application that stores "messages" in array list
and writes new entries to a disk file at the end. This file is used
incase the user choses to restart the program. When the program is
restarted the messages are replayed so the application knows where it
is up to.

I am not allowed to use a **database** I have been instructed to use a
flat file. The application I am replacing does that.

Everything works fine until someone wants to delete a message from the
list. In the Arraylist I simply remove the entry. Which is easy.

However for the file I re-create (delete and re-create) the entire
file with the new records - which seems a waste and exposes possible
danger if the users shuts the application down while re- creating the
file. I know this is small, but I would like to remove all risks.

I am writing the file as binary file stream, with a "message" length
followed by the variable length messages.

Is there any way I can deleted records in the centre of the file
without recreating the file?

Failing deleting the records is there a way I could rewrite a record
in the current file to indicate it should not be reloaded on restart.
I have plenty of space free in the records for some flag.

I know that a database is a better way to do this however I have been
told not to use a database.

Any suggestions.

Stuart

Nov 16 '05 #2
Hi Stuart,

Cody has the best answer... and the most common method for solving that
problem.

If the file is really huge, and you don't feel like rewriting it, you could
add a field to your data that sets a "deleted" value. Use the Seek() method
to move to a specific file location. You will have to track the location of
every record you read, and when you user "deletes" it, move to the location
and mark the record as "deleted." Then, when you re-read it, skip this
record. This is a lousy method unless you control everything going into
and out of your file, so really, you should use Cody's solution first. (in
fact, if you have less than 100,000 records, I'd nominate this solution as
the biggest waste of time imaginable).

--- Nick

"cody" <no****************@gmx.net> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Why don't you simply rewrite the date in a *new* file, and after everything has been written, delete the old file and rename the new file with the name of the original file.

--
cody

Freeware Tools, Games and Humour
http://www.deutronium.de.vu || http://www.deutronium.tk
"Stuart Norris" <st**********@yahoo.com.au> schrieb im Newsbeitrag
news:51**************************@posting.google.c om...
Dear Readers,

I am developing an application that stores "messages" in array list
and writes new entries to a disk file at the end. This file is used
incase the user choses to restart the program. When the program is
restarted the messages are replayed so the application knows where it
is up to.

I am not allowed to use a **database** I have been instructed to use a
flat file. The application I am replacing does that.

Everything works fine until someone wants to delete a message from the
list. In the Arraylist I simply remove the entry. Which is easy.

However for the file I re-create (delete and re-create) the entire
file with the new records - which seems a waste and exposes possible
danger if the users shuts the application down while re- creating the
file. I know this is small, but I would like to remove all risks.

I am writing the file as binary file stream, with a "message" length
followed by the variable length messages.

Is there any way I can deleted records in the centre of the file
without recreating the file?

Failing deleting the records is there a way I could rewrite a record
in the current file to indicate it should not be reloaded on restart.
I have plenty of space free in the records for some flag.

I know that a database is a better way to do this however I have been
told not to use a database.

Any suggestions.

Stuart


Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: raykyoto | last post by:
Hi all, I'm sure this is a popular question that comes up every few months here. Indeed, I've looked at some of the past postings, but I would like to ask things differently. Basically, I'm...
1
by: Heather | last post by:
I know this is a painful question and I have searched the group for past responses and none of the responses seem to cover my specific need. We have a table that contains fields like ID, Yr,...
3
by: Mike Turco | last post by:
I'm working on an application that imports and exports tons of CSV data, like 64,000 records per file, and six or seven files in a set. First off, by the tine I import a few hundred thousand...
1
by: KC | last post by:
Hello, I am using Access 2002. WinXP, Template from MS called Orders Mgmt DB. I have tweaked this DB to work for our small co. It has worked pretty well up until I made the mistake of deleting...
13
by: Bob Darlington | last post by:
I have a repair and backup database routine which runs when a user closes down my application. It works fine in my development machine, but breaks on a client's at the following line: If...
22
by: Daniel Billingsley | last post by:
Ok, I wanted to ask this separate from nospam's ridiculous thread in hopes it could get some honest attention. VB6 had a some simple and fast mechanisms for retrieving values from basic text...
12
by: J. G. | last post by:
I'm looking at rewriting some stand-alone Pro*COBOL applications that read flat files and spit out some reports. Is there any way to mimic COBOL's ability to read lines from a flat file into a...
11
by: shriil | last post by:
Hi I have this database that calculates and stores the incentive amount earned by employees of a particular department. Each record is entered by entering the Date, Shift (morn, eve, or night)...
15
by: lxyone | last post by:
Using a flat file containing table names, fields, values whats the best way of creating html pages? I want control over the html pages ie 1. layout 2. what data to show 3. what controls to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.