Results 1 to 5 of 5
  1. #1
    rileannas is offline Member
    Join Date
    May 2011
    Posts
    3
    Rep Power
    0

    Default 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:


    Java 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();
    
    	}
    
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    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?

  3. #3
    rileannas is offline Member
    Join Date
    May 2011
    Posts
    3
    Rep Power
    0

    Default

    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.

  4. #4
    rileannas is offline Member
    Join Date
    May 2011
    Posts
    3
    Rep Power
    0

    Default

    Solved my problem using this trick: BrainJar.com: Communicating With the Host

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. Bug Reading txt files
    By MHardeman25 in forum New To Java
    Replies: 4
    Last Post: 08-13-2010, 11:03 PM
  2. Reading .dat files in java
    By anilreddy76 in forum Advanced Java
    Replies: 2
    Last Post: 07-23-2010, 02:00 PM
  3. Reading .bin files
    By spatel14 in forum New To Java
    Replies: 3
    Last Post: 06-22-2010, 05:39 PM
  4. Reading .txt files
    By cvcs1 in forum New To Java
    Replies: 3
    Last Post: 01-20-2010, 10:07 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •