Edit text file?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a text file which stores user input. Later if user edited the input
data from a input form. How can I update the input text file? If update the
text file too often, would it cause problem?

Thanks in advance for any help.
 
Nina said:
I have a text file which stores user input. Later if user edited the
input
data from a input form. How can I update the input text file?

For small text files, the simplest solution is to rewrite the whole file.
This doesn't mean deleting the file and then creating a new one, but it
means setting the file's length to 0 using 'FileStream.SetLength' and then
write the data to the file using 'System.IO.StreamWriter'.
If update the text file too often, would it cause problem?

This depends on the size of the file and the intervalls between the updates.
 
Thank you so much for your help. Will 5 to 10 pages's text file be
considered as a small text file?

Nina
 
Nina said:
Will 5 to 10 pages's text file be
considered as a small text file?

I consider everything < 10 KB a "small file", but that's only my personal
opinion.
 
Since the text file that I'm working on is about 50 KB, I cannot use the way
you suggested previously. Is there any way that fits my application?

Thanks again.

Nina
 
Herfried K. Wagner said:
I consider everything < 10 KB a "small file", but that's only my personal
opinion.

Herfried --

If the data stored in her file is structured in the

keyname=value

format does VB.Net have a replacement for the old
WritePrivateProfileString and GetPrivateProfileString
API calls? I'm new to .Net and many of my old VB6
programs use these functions to store and update user data.
As I convert the old projects to .Net I'd like to use the
framework if possible.

Jim Edgar
 
Nina said:
Since the text file that I'm working on is about 50 KB, I cannot use the
way
you suggested previously. Is there any way that fits my application?

What data are you storing?
How often do you store it?
How often do you read the data?
....
 
What data are you storing?
Below is a sample text file:

Subcatchment Name=sub
ID=1
Description=grid
Area=100
Length=800
Slop=4
%Impervious=10
N-Impervious=0.01
N-Pervious=0.05
DStore-Impervious=1.5
Dstore-Pervious=4.5
Model=Horton
End

Statistics
Location=Chicago
Volume=18.86
Duration=7.73
Time=103.1
Annual Number of Events=57.2
End

sub Infil Data
Max. Infil=25.4
Min. Infil=0.36
Decay Constant=4.14
Recovery Constant=0.005
End
How often do you store it?
How often do you read the data?
For these two questions, it depends on how often user changes those inputs.
It is possible that user edit those valumes frequently. Well, what I'm trying
to do is to read the text file and put it into a global arraylist when user
opens the project. While user working with the project, I just simply update
the arraylist. When user close the project, then I writ e the arraylist back
to the text file. Do you think this is a good way to handle it?

Thanks again.

Nina
 
Nina said:
Below is a sample text file:

Subcatchment Name=sub
ID=1
Description=grid
Area=100
Length=800
Slop=4
%Impervious=10
N-Impervious=0.01
N-Pervious=0.05
DStore-Impervious=1.5
Dstore-Pervious=4.5
Model=Horton
End

Statistics
Location=Chicago
Volume=18.86
Duration=7.73
Time=103.1
Annual Number of Events=57.2
End

sub Infil Data
Max. Infil=25.4
Min. Infil=0.36
Decay Constant=4.14
Recovery Constant=0.005
End

For these two questions, it depends on how often user changes those
inputs.
It is possible that user edit those valumes frequently. Well, what I'm
trying
to do is to read the text file and put it into a global arraylist when
user
opens the project. While user working with the project, I just simply
update
the arraylist. When user close the project, then I writ e the arraylist
back
to the text file. Do you think this is a good way to handle it?


I think that's a good way!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top