.txt files

I had some problems writing .xml files. Therefore I creating a new file with .txt extension and used FileWriter to write to it. It works very well and I can therefore use it to save and load, but what are your views about this? Do you think I should continue using it? Thanks in advance.

theres nothing wrong with using .txt files, php still uses them for customizing it. But everyone seems to be changing to XML based configuration files because it is a lot more well structured, validated and there are many parsers for it for pretty much every programming language now, it has become a sort of industry standard now i think. You can use XML as a sort of middle man for communicating with separate entities as well. But if its just a stand alone thing for your program then go for it, if XML isn’t for you.

I will learn it slowly because its codes are quite new to me (in Malta I think we don’t study .XML files at Advanced Level and I am only 15). For now I will use .TXT files and then switch over when I feel more confident. Thanks a lot for your reply. It helped me get on the right track and understand better my situation.

Nothing wrong with plain text storage if it’s good enough. XML is overused and abused often nowadays anyway, it’s not appropriate for everything.

You have options:

XML - heavy weight. Well structured. Can have a specific schema and there are plenty of tools that know how to use that to help with editing. Hand-editing otherwise is kind of painful… and I say this as someone who has used XML for nearly every kind of configuration imaginable. In many cases where no predefined schema was possible.

JSON - light weight, extremely so. Easy to type. It’s basically shrunk down JavaScript and a compliant parser can be written in few hundred lines. (https://meta-jb.svn.sourceforge.net/svnroot/meta-jb/trunk/dev/ext/json/src/main/java/org/progeeks/json/JsonParser.java) For example, that parser reads .json files and turns them into Maps, Lists, and values… and there is a printer object that can reverse the process. Mythruna uses this for its user information database.

Properties files - if you don’t require much hierarchy this is the absolute simplest way of configuring Java apps since the reader and writer are already built right in to Java. And chances are that most Java developers are already very familiar with this format.

Then there would be alternative ultra heavy version as well. Using a embedded SQl like HSQL and store everything in a relational Schema.

Pro: Simple sql is easy and powerfull

Possibility to have more advanced tasks that would need to be implemented by hand else. (Like joins)

Also can be used with any tool that speaks jdbc, wich is quite much.

Depending on needs might be even more perfomant than other solutions, depending on intelligence of used sql system.


Mainly the bit more stuff to do to implement it, but usally this relativates due to the pro’s of sql as a language for everything more complex.

Relational Schema needed, so if the data can not be stored in this form, then this does not work.

Yeah, I was talking config files. I presumed this would be something editable outside the tool and any file-based thing wins hands down in that case… unless it ends up getting used like a database.

Note: Mythruna also uses an embedded database (hsql in fact) for its world data. Didn’t mean to steer anyone wrong. The json files are per-user buckets for whatever random stuff I want to throw in… and easily edited should I need to do so. Since it’s schemaless it makes it really easy to throw in additional data without affecting anything. For example, adding total online time to each user only required a small code change to track the time. Storage was automatic.

Interesting. Thanks :slight_smile: