Hi guys,
Today I had a look at files and therefore I’d like to create a GUI application that allows me to type a sentence or a word and store it to a text file. The reason for this is that, when I come across an interesting word or sentence I like to keep it somewhere for future reference, which means that the new word/sentence needs to be appended at the end of the file, without overwriting anything. It should also allow for multiple languages, but I don’t see that being a problem.
Following from other applications I developed, and the advices kindly given, I’ll leave the GUI as a last thing (will do it with GridBagLayout of course), so I’ll first create an application that takes a sentence/word as a hardcoded string.
The way I envisage this, providing you guys think it is a good idea, is to have a JTextArea that takes the sentence and then an action button (Save) that will allow the application to save the input to a text file.
I’ve read a bit about Sequential-access text files and object serialization. I’m a bit torn between one and the other, and here is why: I don’t really need to amend the sentence/words I write, the idea is that, I write them to file and they are there for when I want to open the file and take a look at them, but then again, what happens if I make a mistake, misspell a word and so on? Wouldn’t I need to amend it?
My understanding is that with sequential access you can’t amend things, you can only re-write the whole file whereas with object serialization you can.
So, what do you guys suggest? Do you have any advice as to how to build it?
thanks
Recommended Answers
Jump to PostNo, especially when writing new code always start off with printStackTrace() everywhere. You never know when the next bug is going reveal itself, and when it does you want all the info you can possibly get.
Jump to PostI didn't know that calls from outside methods were not allowed
You know that you can't put any kind of executeable code just lying around in a class. It has to be in a method or an initialiser. Method calls are no different than any other executable code …
Jump to PostDon't have linux here so I can't say.
But why not use the File constructor that goes
public File(String parent, String child)
Creates a new File instance from a parent pathname string and a child pathname string.... the parent pathname string is taken to denote a directory, and the child pathname …
Jump to PostRight idea, wrong syntax for a method call. It goes like this:
String myDir = ..... (maybe from system properties)
String fileName = .....
File f = new File(myDir, fileName); // creates a File object with that file in that dir
Jump to PostIt just avoids the problem of you having to get the right OS-dependent separator.
All 39 Replies
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.