-
Reading from .txt files
I'm making an advanced search applet for the publications of a science lab. They only have about 300 so I didn't bother teaching myself SQL, it was easy enough to keep all the info for articles (author, journal, year, etc) in a .txt file that acts as a database.
I first wrote a standalone program that works nicely, but after making an applet version it doesn't run at all - a blank screen comes up when I load the html doc it's embedded in. A bit of digging gave me this error message:
java.security.AccessControlException: access denied (java.io.FilePermission publications.txt read)
The publications.txt file is kept in the same folder as the applet source code and html document, but I can't access it for some reason. I am using BufferedReader to read the info from it, should I use something else?
Here is the relevant method:
Code:
private void buildList () {
BufferedReader reader;
articles = new ArrayList<Article>();
String inputLine;
try{
reader = new BufferedReader(new FileReader("publications.txt"));
inputLine = reader.readLine();
while (inputLine != null) {
Article.process(inputLine, articles); //creates a new Article and adds it to the list
inputLine = reader.readLine();
}
reader.close();
}catch(IOException e) {
e.printStackTrace();
}
}
-
Must this be an applet that is displayed via a web page, or can it be a stand-alone gui such as a JFrame? If it must be delivered via the internet, have you using a JNLP program (though this may not work as well on a Mac with Firefox)? Also, have you considered adding the text file to the jar file?
-
Yes, it's for the lab's website so it needs to be on the internet. I have not tried jar or JNLP, I am pretty new to Java (1 year experience). I'll look into them and let you know if it works.
-
-
Thanks for sharing your solution!