Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how can an applet read a file on the hard disk,when the applet is run in a browser?

 
gagan sharma
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Will any java master tell me, that if I run an applet in a browser,can the applet read a file from the hard disk,if so how?
I've done this using the appletviewer.
thx in advance!
------------------
 
aseem kapoor
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JUST GIVE THE PROPER PATH WHERE UR FILE IS LOCATED IN ADDRESS
TEXTFEILD OF THE BROWSER.
 
Matthew X. Brown
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe that security restrictions on applets will disallow you from reading from the client's disk. However, if you mean to say that you want to use files on the server-such as a flat file full of parameters, and read it into your applet-Possibly-Create a javabean to open a java io inputstream...Maybe use a filereader with a bufferedinput class. Then call the javabean in your applet.
 
gagan sharma
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thx for the reply dear,but i need to call a file from the local hard disk in the browser using applets using some generalized way,may be it is possible by making some changes in the policytool or some other way! ,if u or somebody else know that then do tell me!
gagan!
Originally posted by Matthew Brown:
I believe that security restrictions on applets will disallow you from reading from the client's disk. However, if you mean to say that you want to use files on the server-such as a flat file full of parameters, and read it into your applet-Possibly-Create a javabean to open a java io inputstream...Maybe use a filereader with a bufferedinput class. Then call the javabean in your applet.


------------------
 
Matthew X. Brown
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for the poor response- but let me ask- what exactly do you intend on doing with this read from the file- are you going to display the data, parse the data- how, from a functional standpoint, is your applet going to work? This might help someone getting an answer to you.
 
Matthew X. Brown
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is some code I wrote to get a scrolling test applet to pick up data from a local file......Unfortunately the applet component I used was from Symantec----> but it should give you an idea of what you need to do.
/*
A basic extension of the java.applet.Applet class
*/
import java.util.Vector;
import java.util.*;
import java.io.*;
import java.awt.*;
import java.applet.*;
import java.applet.Applet;
import symantec.itools.multimedia.ScrollingText;
public class Applet1 extends Applet {
public static String [] data;
public static Vector lstring;
public static File f = new File("c://test.txt");
// private Container container;

public static String [] getData(){
System.out.println("Get Data Method");
Vector lstring = new Vector();
try{
System.out.println("Entered the try");
// File f = new File("c:/visualcafe/projects/test.txt");
BufferedReader in4 =
new BufferedReader(
new FileReader(f));
System.out.println(in4);
String s = new String();
while((s = in4.readLine()) != null){
System.out.println(lstring);
lstring.addElement(s+"\n");
}
in4.close();
data = new String [(lstring.size())];
lstring.copyInto(data);



}catch(IOException e){
System.out.println("File not found");
}
return data;
}
public void init()
{
// Take out this line if you don't use symantec.itools.net.RelativeURL or symantec.itools.awt.util.StatusScroller
symantec.itools.lang.Context.setApplet(this);
// This code is automatically generated by Visual Cafe when you add
// components to the visual environment. It instantiates and initializes
// the components. To modify the code, only use code syntax that matches
// what Visual Cafe can generate, or Visual Cafe may be unable to back
// parse your Java file into its visual environment.
//{{INIT_CONTROLS
setLayout(null);
setSize(426,266);
try {
{
String[] tempString = new String[5];
tempString[0] = "get";
tempString[1] = "some";
tempString[2] = "text";
tempString[3] = "in";
tempString[4] = "here";
//scrollingText1.setMessageList(tempString);
scrollingText1.setMessageList(this.getData());
}
}
catch(java.beans.PropertyVetoException e) { }
try {
java.net.URL[] tempURL = new java.net.URL[1];
tempURL[0] = new java.net.URL("file:///C:/My Documents/issues.html");
scrollingText1.setLinkToList(tempURL);
}
catch (java.net.MalformedURLException error) { }
catch(java.beans.PropertyVetoException e) { }
add(scrollingText1);
scrollingText1.setBounds(48,36,333,79);
//container = new Container();
/*try {
scrollingText1.setMessageList(this.getData());
}
catch(java.beans.PropertyVetoException e) { }
add(scrollingText1);


scrollingText1.setBounds(48,24,344,75);
*/

//}}
}
//public void start(){Applet1 ap = new Applet1();}
//{{DECLARE_CONTROLS
symantec.itools.multimedia.ScrollingText scrollingText1 = new symantec.itools.multimedia.ScrollingText();
//}}
}
 
Matt DeLacey
Ranch Hand
Posts: 318
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Netscape and IE, in particular, have security restrictions on this. You simply cannot have an APPLET running on another server access the file system on a local machine. There is a way you can go applet making your applet a trusted applet, but it's kind of difficult and getting examples from Sun on this is like pulling teeth. I'm not sure if signing your aplet would let you access the local foile system, but it DOES let you open sockets with something other than the server on which the applet is run (which is something you CAN'T do with an untrusted applet). It is a shame but you can imagine the huge security problems that would result. I know it's not what you want to hear, but you gotta give up the dream, 'cuz it just ain't gonn happen!

Matt
 
gagan sharma
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Matthew & others!
Let me tell u what i want to achieve:
Consider a SERVER that is connected to a number of clients.At the client side a number of data entry operations take place which are updated at the server side.Suppose a particular data entry operation is quite lengthy & after hours of entry,if the server connection is lost at that time,the whole data gathered becomes useless,because it is using a JAVA program,it cannot be writtened to the local hard disk.Then next time the connection with the server is restored,the whole operation is to carried out
again.Is there some way to write it to the local machine & read it later when the connection with the server is restored.
So that's the story.
Matthew will u help me out?But i want it the way i told earlier,(using an applet in a browser)
thx
gags!
Originally posted by Matthew Brown:
Sorry for the poor response- but let me ask- what exactly do you intend on doing with this read from the file- are you going to display the data, parse the data- how, from a functional standpoint, is your applet going to work? This might help someone getting an answer to you.

------------------

[This message has been edited by gagan sharma (edited November 10, 2000).]
[This message has been edited by gagan sharma (edited November 10, 2000).]
 
gagan sharma
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey!
Thx for sharing the info.I'm still hopeful for getting the solution.
gags!
Originally posted by Matt DeLacey:
Netscape and IE, in particular, have security restrictions on this. You simply cannot have an APPLET running on another server access the file system on a local machine. There is a way you can go applet making your applet a trusted applet, but it's kind of difficult and getting examples from Sun on this is like pulling teeth. I'm not sure if signing your aplet would let you access the local foile system, but it DOES let you open sockets with something other than the server on which the applet is run (which is something you CAN'T do with an untrusted applet). It is a shame but you can imagine the huge security problems that would result. I know it's not what you want to hear, but you gotta give up the dream, 'cuz it just ain't gonn happen!

Matt

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic