Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Aug 13th, 2007, 9:48 PM   #11
lectricpharaoh
Caffeinated Neural Net
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Wet west coast of Canada
Posts: 889
Rep Power: 4 lectricpharaoh will become famous soon enough
Quote:
Originally Posted by Keiro View Post
Heh, I got it working now. ^^'' Had to find a script which read the while of a file then I wrote it back with the new stuff at the beginning and added a few \n's.

What I ment by not wanting to load into main memory is cos I don't want to load large files like a few MB then rewrite them. I know its not much but still. =P
How does your approach solve this problem? You cannot add to the beginning of a file directly. If you wish to add to the beginning, you must do one of two things:

Method one: Read the entire file into memory, and modify the contents there. Write out the modified file when done. Slight variation on this is to use a memory-mapped file (useful if the file's size exceeds physical memory available).

Method two: Create a new file with your new line. Append the old file's contents to it. Delete the old file, and rename the new one to match the old one.

This brings me back to my point about your reasons for doing this. For example, if you're treating each line in the file as an element, and wish the file to act as a stack of elements with the beginning of the file being the top of the stack, why not just alter your code so the end of the file is the top of stack? This is just an example; since you won't tell us why you're doing this, we can't be of any more help than this.
__________________
A man's knowledge is like an expanding sphere, the surface corresponding to the boundary between the known and the unknown. As the sphere grows, so does its surface; the more a man learns, the more he realizes how much he does not know. Hence, the most ignorant man thinks he knows it all. - L. Sprague de Camp
lectricpharaoh is offline   Reply With Quote
Old Aug 14th, 2007, 3:01 AM   #12
Keiro
Newbie
 
Join Date: Nov 2006
Location: Here!!!
Posts: 7
Rep Power: 0 Keiro is on a distinguished road
But I've fixed it now. =P

I read the WHOLE file into memory then wrote the new text with the original after it. Kinda the thing I didn't want to do BUT it works.
Keiro is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
OnlineTextEditor.Com! Sane Show Off Your Open Source Projects 43 Jun 16th, 2006 8:55 AM
Read and write to one file nnxion C 3 Apr 11th, 2006 5:10 PM
How to read a line of from a file aznluvsmc C 12 Oct 22nd, 2005 5:36 PM
After execution - Error cannot locate /Skin File? wchar Visual Basic 1 Mar 5th, 2005 9:04 PM
airport Log program using 3D linked List : problem reading from file gemini_shooter C++ 0 Mar 2nd, 2005 4:12 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:16 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC