File Read/Write
-
Hello, I have a text file with the following layout. COMMAND1 ITEM1 Value1 Value2 Value3 Valu4 ITEM2 Value1 Value2 Value3 Valu4 ITEM3 Value1 Value2 Value3 Valu4 ITEM4 Value1 Value2 Value3 Valu4 ... ITEM_N COMMAND2 ITEM1 Value1 Value2 Value3 Valu4 ITEM2 Value1 Value2 Value3 Valu4 ITEM3 Value1 Value2 Value3 Valu4 ITEM4 Value1 Value2 Value3 Valu4 ... ITEM_N COMMAND3 ITEM1 Value1 Value2 Value3 Valu4 ITEM2 Value1 Value2 Value3 Valu4 ITEM3 Value1 Value2 Value3 Valu4 ITEM4 Value1 Value2 Value3 Valu4 ... ITEM_N .... COMMAND_N In this file, I have to insert new items, or change values of items or delete existing items. For suppose if I want to insert new item under "COMMAND1", what I am doing is, seeking the pointer to the end of "COMMAND1", writing remainig text into a temporary file, inserting my new text, then appending the text which is stored in temporary file. But I guess, it is not a best method. It takes much time every time I insert/edit text. Is there any other alternative to do this. Can anybody tell what is the best method to do this. Thanks & regards, Chito
-
Hello, I have a text file with the following layout. COMMAND1 ITEM1 Value1 Value2 Value3 Valu4 ITEM2 Value1 Value2 Value3 Valu4 ITEM3 Value1 Value2 Value3 Valu4 ITEM4 Value1 Value2 Value3 Valu4 ... ITEM_N COMMAND2 ITEM1 Value1 Value2 Value3 Valu4 ITEM2 Value1 Value2 Value3 Valu4 ITEM3 Value1 Value2 Value3 Valu4 ITEM4 Value1 Value2 Value3 Valu4 ... ITEM_N COMMAND3 ITEM1 Value1 Value2 Value3 Valu4 ITEM2 Value1 Value2 Value3 Valu4 ITEM3 Value1 Value2 Value3 Valu4 ITEM4 Value1 Value2 Value3 Valu4 ... ITEM_N .... COMMAND_N In this file, I have to insert new items, or change values of items or delete existing items. For suppose if I want to insert new item under "COMMAND1", what I am doing is, seeking the pointer to the end of "COMMAND1", writing remainig text into a temporary file, inserting my new text, then appending the text which is stored in temporary file. But I guess, it is not a best method. It takes much time every time I insert/edit text. Is there any other alternative to do this. Can anybody tell what is the best method to do this. Thanks & regards, Chito
Well the assumption is rather correct but there is too many calls to the file. you should read the content of the file to the memory. Then do all the opertions (parsing, reallocation etc) and then the buffer (with the new value) should be written to the file again. The content fo your file looks like it can be easly stored by xml. And will be easier to parse. Have a good day
-
Hello, I have a text file with the following layout. COMMAND1 ITEM1 Value1 Value2 Value3 Valu4 ITEM2 Value1 Value2 Value3 Valu4 ITEM3 Value1 Value2 Value3 Valu4 ITEM4 Value1 Value2 Value3 Valu4 ... ITEM_N COMMAND2 ITEM1 Value1 Value2 Value3 Valu4 ITEM2 Value1 Value2 Value3 Valu4 ITEM3 Value1 Value2 Value3 Valu4 ITEM4 Value1 Value2 Value3 Valu4 ... ITEM_N COMMAND3 ITEM1 Value1 Value2 Value3 Valu4 ITEM2 Value1 Value2 Value3 Valu4 ITEM3 Value1 Value2 Value3 Valu4 ITEM4 Value1 Value2 Value3 Valu4 ... ITEM_N .... COMMAND_N In this file, I have to insert new items, or change values of items or delete existing items. For suppose if I want to insert new item under "COMMAND1", what I am doing is, seeking the pointer to the end of "COMMAND1", writing remainig text into a temporary file, inserting my new text, then appending the text which is stored in temporary file. But I guess, it is not a best method. It takes much time every time I insert/edit text. Is there any other alternative to do this. Can anybody tell what is the best method to do this. Thanks & regards, Chito