Link to home
Start Free TrialLog in
Avatar of Cheney
Cheney

asked on

Loading data into an Applet

Hello all,

I'm having trouble making an applet load data.

I have a Java application that runs on my local machine that generates 10000 integers and saves them to a file using:

            FileOutputStream file = new FileOutputStream("demo.map");
            DataOutputStream out = new DataOutputStream(file);

            out.writeInt(map.MAP_WIDTH);
            out.writeInt(map.MAP_HEIGHT);

            etc...

This works fine.  The next Java program is an Applet (extends JApplet), that should load the data.  It works fine when running in AppletView on my local machine, however after uploading the classes and the data file (demo.map) to a server, my applet always crashes.

I've looked into the crash an found that the reason that it is crashing is because when reading back the data from demo.map, all the values are different from the saved ones.  Heres the applet code:

            URL source = new URL(getCodeBase(), "demo.map");
            DataInputStream in = new DataInputStream(source.openStream());

            map.MAP_WIDTH = in.readInt();
            map.MAP_HEIGHT = in.readInt();

I know that demo.map contains the correct data (I looked at it in a hex viewer) and yet this code is reading in different data!

I have tried uploading the data file as both a binary and an ASCII file in my WSFTP but the results are identical.

What is the problem?
Thanks for your help.
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Cheney
Cheney

ASKER

Yup, the source is fine.  The URL points to the place where I uploaded the file.
Avatar of Cheney

ASKER

Oddly enough I've fixed it.  The problem seems to have been the server and the .map file extension.
ok, the http server must have been doing some special handling of .map files.