Results 1 to 7 of 7
Thread: Reading a user made text file?
- 01-13-2012, 07:30 AM #1
Reading a user made text file?
I'm making a little application that is a study helper for history
What it does is read a text file (written in a specific format) an makes an array of all of the terms and definitions found in the text file, then can quiz you in a few different ways, such as giving the user a term and five definitions and they have to match it correctly.
I'm pretty far down the line with it, but there's one thing I don't know how to do.
The program should be pretty robust, in that the set of terms and definitions should be able to change without having to edit the source. When the application is done, I want to be able to simply replace the text file (in the same folder as the app) and have the app read the new text.
How do you do this? Thanks.
-
Re: Reading a user made text file?
Give it a menu or JButton whose Action opens a JFileChooser, allows the user to choose a file, then tries to open and use that file -- all within try/catch blocks of course.
- 01-13-2012, 07:51 AM #3
Re: Reading a user made text file?
Is there a way to do it where you could just put the text file in the same folder as the application?
-
Re: Reading a user made text file?
What if you put your application in a Jar file, which is pretty darn likely. Do you mean to put the text files in the jar file? Is it OK if these files cannot be modified? If so, then sure, put them in the Jar (though I'd put them in their own directory), but be sure to refer to them as resources, not files.
- 01-13-2012, 08:04 AM #5
Re: Reading a user made text file?
But if I put it in a Jar, then I CAN'T modify it?
The point is that I should be able to edit the study sheet whenever I want.
It's not the worst thing to have to select the text file every time you open the program, though...
-
Re: Reading a user made text file?
Jars are not made for modification as the data is stored in zip-file format. Modification isn't impossible but there are usually better ways to solve your problem.
It's not the worst thing to have to select the text file every time you open the program, though...
- 01-13-2012, 09:23 AM #7
Senior Member
- Join Date
- Jun 2007
- Location
- Bali, Indonesia
- Posts
- 762
- Rep Power
- 14
Re: Reading a user made text file?
You can get the current working directory of your executing program using the following snippet:
Java Code:System.getProperty("user.dir")
Last edited by wsaryada; 01-13-2012 at 09:39 AM.
Website: Learn Java by Examples
Similar Threads
-
Arrays made from user input
By sonofJack3 in forum New To JavaReplies: 15Last Post: 12-01-2011, 07:18 AM -
Reading from a text file, then writing back to Text Area in Reverse
By medic642 in forum New To JavaReplies: 8Last Post: 07-17-2011, 03:38 PM -
Help reading a text file.
By Kristoba in forum New To JavaReplies: 5Last Post: 03-11-2010, 09:42 AM -
Reading in a text file
By TheRealHoff in forum AWT / SwingReplies: 10Last Post: 02-08-2010, 12:47 AM -
reading text file
By trofyscarz in forum New To JavaReplies: 1Last Post: 02-05-2010, 03:24 AM
Bookmarks