Results 1 to 3 of 3
Thread: File Input - Signed JAR Applet
- 01-12-2010, 11:07 PM #1
Member
- Join Date
- Jan 2010
- Location
- Pennsylvania
- Posts
- 3
- Rep Power
- 0
File Input - Signed JAR Applet
Hello, I have been having quiet some trouble trying to solve my problem.
I have a type of game applet that I have been developing.
In the long run, the applet is going to be hosted on my server in an HTML file.
The applet is compressed into a JAR along with all the files and images needed.
I am trying to open a text file that is in the JAR, read it, and use the content accordingly.
When I test the signed JAR applet locally on my machine, in an HTML file, it works flawlessly every time.
When I upload the signed JAR to my server and then try to load it in an HTML file, it throws a "File Not Found" exception.
All the other images load, they are also compressed in the JAR.
I even tried placing copies of the file outside of the jar in the same directory, and still no luck.
My objective is to be able to have the applet hosted on my web server, and it be able to find the file that is either compressed in the JAR, or located in the same directory as the applet.
My code to open the "file".
Thanks!Java Code:File file = new File("level1.txt"); Scanner scanner = new Scanner(file);
- 01-13-2010, 02:40 AM #2
getting the text file from within the .jar file is probably the simpler approach for an applet, otherwise you could use a URL and fetch it from a stored location on the same server where the applet was served from, and this probably would need a configuration setting in the applet init parameters, so all this is a lot of work to do if the file is read-only and doesn't ever change (the same for ever invocation of the applet and for every user who would use the applet). If the file needed to be different than the external file store would make more sense right.
So , jar files are in the classpath, we can use a feature of the class loader to get a file, or a 'resource' located on the classpath as an input stream., the 'getResourceAsStream()'
where the filename can be in a folder, e.g. package within the jar file (classpath). and we would denote this with "/" path delimiters.Java Code:InputStream in = LoadFromJarFile.class.getResourceAsStream("fileName.txt"); if (in == null) { // unable to find the file in the class path (e.g. jar file) // do error here. } Scanner scanner = new Scanner(in);
- 01-13-2010, 03:36 AM #3
Member
- Join Date
- Jan 2010
- Location
- Pennsylvania
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
Signed Java Applet to read a file on hard drive?
By ollyworks in forum Java AppletsReplies: 2Last Post: 09-11-2009, 10:08 PM -
Applet with Signed JAR throws AccessControlException in AppletViewer
By Technolithic in forum Java AppletsReplies: 1Last Post: 07-27-2009, 11:59 AM -
[SOLVED] signed applet, or what
By AXH in forum Java AppletsReplies: 2Last Post: 10-10-2008, 01:28 AM -
Copy a .swf file from server side to client using signed applet
By Imoracle in forum Java AppletsReplies: 2Last Post: 10-05-2008, 06:13 PM -
run java signed applet in vista
By nanaji in forum Java AppletsReplies: 7Last Post: 05-14-2008, 11:59 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks