Solved

document loading from Mac browser

Posted on 1998-11-19
6
168 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
  • 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
Independent Software Vendors: 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

Independent Software Vendors: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SHA2 certs for IIS AND Java? 2 122
String array comparison 4 45
jboss 7.1 start up error 1 63
printf performancy 11 84
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues undeā€¦
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilationā€¦
The viewer will learn how to implement Singleton Design Pattern in Java.
This video teaches viewers about errors in exception handling.

749 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