• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

problem with URL -> Applet

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi, i have a little problem running my applet. it's supposed to get a file from the WWW and display its contents as a string inside a JTextArea. the file on the web is a simple .txt containing little text, say one sentence, its irrelevant here. the file is read in inside a different class that the applet calls. however, there seems to be a problem with that - maybe it has something to do with Applet restrictions. anyway. here goes:

the applet (i removed all irrelevant applet construction objects like buttons etc) -

public class Applet1 extends JApplet {

private JTextArea sisestaJutt;
private String juttVeebist;

public void init() {

URLReader veebist = new URLReader();

try {
juttVeebist.equals( veebist.reader());
}
catch(Exception e) {
}

Container sisu = new Container();
sisestaJutt = new JTextArea(juttVeebist);
sisu = getContentPane();
sisu.setLayout( new BorderLayout() );
sisestaJutt.setBorder(brdr);
sisu.add(sisestaJutt, BorderLayout.CENTER);

}

}


the called class (& method) -

public class URLReader {
public static String reader()

throws Exception {

URL jjstreet = new URL("http://www.anydomain.com/file.txt");
BufferedReader input = new BufferedReader(
new InputStreamReader(
jjstreet.openStream()));

String inputLine = input.readLine();

input.close();

return inputLine;


}
}
 
author and deputy
Posts: 3150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to Javaranch Ardi.
I'm moving your question to Applets forum, folks there may help you.
Please continue your discussion here
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Applet Security FAQ:


1. What are applets prevented from doing?
In general, applets loaded over the net are prevented from reading and writing files on the client file system, and from making network connections except to the originating host.


So if the text file is on a server other than the one you downloaded the applet from, you will get a security exception.
 
Yeah, but does being a ninja come with a dental plan? And what about this tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic