Solved

document loading from Mac browser

Posted on 1998-11-19
6
169 Views
Last Modified: 2010-03-30
I've written an applet that reads text from a file on the server.  The file is in the same directory as the applet.  I've verified that it's got the right filename and path.  However, no data is getting read in.  This applet works on win95 and NT in Netscape 3 and 4 and in IE3 and IE4.  It also works on UNIX, both SGI and Solaris.  However, it is currently failing on both Netscape 3 and 4 on the Macintosh.  This applet is running all 1.02 JDK code, and I tried compiling with both a 1.02 and 1.1.x compiler.  

In every case, no data is showing up.  Here's the snippet where I read in the data:

try {
  url = new URL(getCodeBase, "data");
  stream = url.openStream();
 
  is = new DataInputStream(stream);
 
  while (is.available() > 0) {
    v.addElement(is.readLine());
  }

-Tony
0
Comment
Question by:rembo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 5

Expert Comment

by:fontaine
ID: 1227904
Just a remark. The way you are using the readLine() method of DataInputStream does not
seem correct to me. I would personally write the following:

String line = "";

while((line = is.readLine()) != null) {
    v.addElement(line);
}

Could you replace your current code by the one above and have a try?
0
 
LVL 6

Expert Comment

by:gadio
ID: 1227905
Tony, have you tried it on IE for mac? Also, on what stage does that code hanges? after the openStream? After the first readLine? Maybe the EOF is not tested correctly (as fontaine suggests).
0
 
LVL 4

Author Comment

by:rembo
ID: 1227906


Actually, fontaine's feedback fixed my problem.  It's really
strange though because, technically, my code is correct.  I
should be able to use the available() routine to determine
if I can read from the file or not, but it doesn't appear
to work on the Mac.  Fontaine, if you post a null message
as an answer, I'll be happy to give you the points.  

Thanks!

-Tony

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Accepted Solution

by:
fontaine earned 100 total points
ID: 1227907
:-)
0
 
LVL 6

Expert Comment

by:gadio
ID: 1227908
Tony, I think you might have a mistake there. You can't use the available() routine since its only indicating "the number of bytes that can be read from this input stream without blocking", so there can actually be more bytes to read from the file but not in the OS / VM buffer. You get to see this sort of bugs a lot when you move your code from one OS to another.
0
 
LVL 5

Expert Comment

by:fontaine
ID: 1227909
I agree with Gadio.  What probably happended is that there was nothing "ready to use"
when the loop was reached. Hence, nothing happended. The code I proposed works because readLine() is blocking until an EOL is reached.
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
In this post we will learn different types of Android Layout and some basics of an Android App.
This video teaches viewers about errors in exception handling.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question