Results 1 to 1 of 1

Thread: Opening a file

  1. #1
    rdjava's Avatar
    rdjava is offline Member
    Join Date
    Jan 2011
    Rep Power

    Default Opening a file

    I have a Jar file containing a class file called Loggin.class which is an applet, there is also another file called MREAManager.class

    the MREAManager.class file loads a file outside of the Jar file called "lgindt.xls" the Loggin.class calls the MREAManager's constructor which then loads the File.
    The file ("lgindt.xls") is at the same location as the Jar file. normally this would be ok and work, but it doesnt seem to find the file.

    i created an HTML file to test the applet, the applet loads fine but doesnt load the file.
    I heard i the URL class but i wasnt sure if that would work or not. if anyone has any ideas please share.
    I actually figured it out. here is the code needed

    URL url;
    URLConnection urlConn;
    InputStream dis;

    url = new URL(dir);

    urlConn = url.openConnection();

    dis = new DataInputStream(urlConn.getInputStream());
    In the code above the URL is hard-wired into the constructor method for the URL class.

    Next, create a URLConnection object named urlConnection by invoking url.openConnection(). Then, this connection is defined to be an input connection by invoking setDoInput() method of the URLConnection class. To make sure that we get a real copy of the data file and not a cached file, we also invoke setUsesCaches(false).
    Last edited by rdjava; 01-30-2011 at 10:31 PM.

Similar Threads

  1. Help opening and reading a file
    By viperlasson in forum New To Java
    Replies: 0
    Last Post: 09-21-2010, 08:32 AM
  2. Opening mp3 file ( not reading )
    By Char in forum New To Java
    Replies: 15
    Last Post: 08-29-2010, 08:09 AM
  3. Opening .html file
    By Prajin in forum New To Java
    Replies: 7
    Last Post: 08-06-2010, 08:20 AM
  4. Error While Opening A PDF file
    By Cluster Storm in forum AWT / Swing
    Replies: 6
    Last Post: 06-07-2010, 07:03 PM
  5. Problem in opening a file
    By Raghav kv in forum New To Java
    Replies: 1
    Last Post: 08-11-2007, 02:55 PM

Posting Permissions

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