Solved

document loading from Mac browser

Posted on 1998-11-19
6
163 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Starting to learn JAVA, 7 59
Java Timer (static) 9 36
ForLoop Example 3 40
javap not working 8 36
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…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

914 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now