How to Update Code of a Serialized file in Java - java

I've made an update to my game in which the save file has been updated, including an array. The problem I have is that the old save file doesn't have this array, so when the code tries to access it it gets an outofbounds error. The obvious solution would be to delete the save file and let the game recreate it, but that would result in the deletion of highscores. I have added a method in the save class but it seems to have no effect, as the original didn't have it.
Is there any way of updating the save file without deleting the data within? Another option might be to create another save file, but it would be tedious to create a new one for every update.
Any help or advice would be greatly appreciated.

Thinking loudly maybe read data from file to the memory, clear data inside file, add missing array to previous file's content and write stream again to the same file?

Related

Storing, retrieveing, editing and deleting data

I am coding a questionbank with netbeans as a school project. I am using a JFrame GUI to enter question data. I need some clever way to store, edit and delete data in some file. I donĀ“t want to use any databases. I already tried solving this with txt files but it is tedious and wont work. I need some option where I can add an entire question to the file and then when I retrieve it retrieve certain parts. The data below is how I tried solving it. I then used a scanner to read the files line by line and stop everytime a "_" is read. Is there any better way to store this. Or can i store this in a 2 dimensional array in the java program itself.If so any help or solution is appreciated
Geography_What is England's capital_Berlin_Manchester_Dover_London_D_3
Maths_What is 2+3_7_9_5_6_C_1
Economics_What is demand_idk_stuff_demand_supply_C_2
Well, if you dont want databases or any external files, the only way to "store" information is to create some data structures to do so. The issue with that is they wont persist past the lifetime of the current running application.
Id advise to use some form of external file, or set up a simple sql db. Its easy and will make the project simpler

Does the File delete() method write on the storage drive itself? (Java)

When you right click a file and click delete, it doesn't actually erase the data. It simply just removes the reference to the file within the Master File Table.
I was wondering what the delete() method in the Java class, File does. Does it remove the reference to the file, allowing the OS to overwrite the data, or does it completely erase the file by writing 0s over it?
Thanks in advance.

Writing a boolean on a specific offset inside a file

I'm currently trying to make a very fast application that can write data to a file very quickly. However, the only way to do this is if I'm able to access a specific offset inside a file and write a boolean there.
First of all, I'm assuming that ObjectOutputStream(FileOutputStream) always writes data to the file the same way, keeping the same structure for the data.
Secondly, what I need to do is to access a specific offset of a boolean inside a boolean[][] inside the file. Is there any Java class that "scrolls" through the data structure created inside a file by OOS?
If not, maybe someone can shed some light on how to do this very fast or on how to do this ensuring the file does not get corrupted (hence the data not getting corrupted).

create a directory like windows explorer and store information a text file

guys i have got a problem in which i have to create a directory which keeps a text file which keeps the information about all the files. Like file created, last modified , type etc.. its not a big deal till i have to maintain this record of the static files(already present in the directory). But what happens when some new files are added, how do i check that the last modified thing. For the static files, initially i have set the class variable as zero and later the variable is compared with the last modified value. My question is what happens when a new file is added ? A new object is created every time a new file is added ?
I tried that way but its turning out to be highly tedious? Am i moving in the right direction? It has to be done in java. In a real fix. Kindly help guys. I hope am clear with my doubt.
Thanks in advance!

delete single line in a text file?

I have created j2me application for read write of text file
now at time of reading I read one line and send it to server. after that I want to remove that line from text file.
I am not getting how to do it. in some example I found solution as copy original file content in one object then remove that string from object and then delete original file and create new with that new object.
I don't think it as good approach. is there any other way to do so???
Edit:
actually problem is like one application is writing some data in text file and my another application read one line send to server and remove that line.
Now if I go with the approach like copy new object and delete file and write new file with new object then I will found one problem
if file is deleted then first application can't found that file so it may create new file
with only one data and second application will create new file based on new object
so my data will be lost
Edit:
Even I tried to do same thing with RMS but when both application is accessing same RMS at that time all data in RMS file are clear. First application open RMS for writing and second Open for sync and delete. but at time when both are opening RMS all data clear.
Is it possible to set lock on RMS file from one application??
No, that's how you do it.
You can't delete a line from the beginning of a file. You would need to re-write the file without that line.
(Note that this is not specific to java)
As records are inserted i was creating single file for single record in one specific folder
now as that file is read by background application and send to server that will be deleted by application.
so it solve concurrency problem in file read write.
i know it is not good approach but i didn't find any other good approach.
Most file systems don't have a mechanism for deleting stuff in the middle. (pretty sure that's the case in j2me). So a standard practice is open a new file; copy the old file up to the point where the unwanted line goes, skip it, then copy the rest of the file. I know it sounds inelegant but that's just how it is :)

Categories

Resources