I have a similar problem. I am totally new to Java and am learning it to
do a very specific task at the moment. My applet will add to a group of
web pages located in a directory mounted locally (i.e. accessible by a
path /home/bla/bla/bla). The applet code will be local, as will the
files I want to read in and process to give an interactive display in a
frame. Will netscape allow the files to be read, if not can I make it so
that it will, or will I have to tackle this problem a completely
different way. The only other way I can think of if I am not allowed to
do this is by having a daemon of some kind which serves the information
to the applet, but I would like to avoid this as it would complicate
things for the user.
Thanks in advance.
--
James Crossley
You can read, writing is another matter.
Read example: ( _ indicates this should all be on one line)
This example will open a file named "filename.txt" in the same directory
as the location of the HTML file and applet class files.
Note this allows you to open the file to read it sequentially so if you
want data at the end of the file you must read all of the content that
comes before it first. I have done this with my Search Engine (IDKSM)
and even though it must read through the whole file it still works
fairly fast.
Writing you are out of luck.
++++++++++++++++++++++++++
int theData;
URL aURL = null;
DataInputStream yourFile;
aURL = new URL(getDocumentBase(), "filename.txt");
yourFile = new DataInputStream(new_
BufferedInputStream(aURL.openStream()));
// then use one of the read methods. readFully, readInt, readShort, etc.
theData = yourFile.readInt();
yourFile.close();
++++++++++++++++++++++++++++++
--
==== Programming my first best destiny! ====
Michael A. Hess Miracle Concepts, Inc.
mh...@miraclec.com http://www.miraclec.com
> In article <s0p3i2...@corp.supernews.com>, Jung Soe
> <ju...@bigfoot.com> writes
> >Need help,
> > Is there any way to make the applet read or write a text file located on
> >local machine.
>
> I have a similar problem. I am totally new to Java and am learning it to
> do a very specific task at the moment. My applet will add to a group of
> web pages located in a directory mounted locally (i.e. accessible by a
> path /home/bla/bla/bla). The applet code will be local, as will the
> files I want to read in and process to give an interactive display in a
> frame. Will netscape allow the files to be read, if not can I make it so
> that it will, or will I have to tackle this problem a completely
> different way. The only other way I can think of if I am not allowed to
> do this is by having a daemon of some kind which serves the information
> to the applet, but I would like to avoid this as it would complicate
> things for the user.
> Thanks in advance.
> --
> James Crossley
You will have to look into "signed applets". They will let you expand the
limits of the Java security model. However, its a lengthy topic. There are
various FAQ's on the net about how to go about this.
The security model does not allow access to the local machine by default. It
runs in a "sandbox" so to say. Although, it does allow you to make Socket
connections back to the serving host system, which allows for the complication
you wish to avoid.
Rafael
de...@swcp.com
Only for the writing aspect.
> The security model does not allow access to the local machine by default. It runs in a "sandbox" so to say. Although, it does allow you
> to make Socket connections back to the serving host system, which
> allows for the complication you wish to avoid.
This is exactly what my example shows. It opens a connection to the
local file for reading. As long as the HTML file and applet are loaded
from the local machine then the local machine is considered to be the
serving host and you can open the file.
I would suggest that you use the Java plugin. The browser loads the
plugin then loads the applet. Using the plugin will allow you to read
and write to your local hard drive. Below are the instructions on how
to download and install the plugin.
Question: How do I run Swing applets in Netscape and Microsoft Web
browsers?
Answer: The latest Netscape Communicator and Microsoft Internet
Explorer Web browsers do not support Swing yet. The new
Netscape Communicator 5.0 will support Swing and should be coming out
sometime during the first quarter of 2000. I don't think that
Microsoft Internet Explorer will ever support Swing. Microsoft views
Java and Swing as too much of a threat to it's company so I
believe that it will stop supporting Java in it's browser. If they do
decide to continue to support Java, it will probably be broken up
support so that your applets don't run properly. That is what they did
before with the previous version of Java (Java 1.1) and that's
why Sun Microsystems took them to court.
If you want both Netscape and Microsoft Browser users on the Web to be
able to view your Swing applets, they will have to
download the Java Runtime Environment, including Java Plug-in from the
Sun Microsystems site at
http://java.sun.com/products/jdk/1.2/jre/download-windows.html. It is
a 6MB download. It's a very simple installation for the user to
make. Once they have done this, then your Swing applets will work
properly on the users computer.
When you want to include your Swing applet in a web page, you have to
slightly change the HTML applet tags that you are use to
using for your older applets. The change that you make simply tells
the applet to first load the Java Plug-In on the users computer
first, then load the applet. This way, your Swing applet will work
properly. You can find the documentation that will tell you how to do
this at: http://java.sun.com/products/plugin/1.2/docs/tags.html
Yours Truly,
Robert Hurd
Code Collection (Owner & Webmaster)
http://www.codecollection.com
FREE Java, CGI & JavaScript Source Code
Yep, but you will have to 'sign' the applet. There are some tools
called 'keytool,' 'jarsigner' and 'policytool' that allow you to play a
little with securities. The concept is simple: You Sign an applet with
a certain code key, and make that key available to the clients. Those
clients can install that key, so that the applet is considered to
be 'trusted.'
Check java.sun.com for more info (or you can always send me a mail :)
Regards,
Jean
Sent via Deja.com http://www.deja.com/
Before you buy.