Applet read file on web

Can applet read file on web?
I try to write an applet that read the file on web i.e. http://lcoalhost:8080/test.txt
The HTML page contain the applet is placed on http://localhost:8080
URI URItemp= new URI("file:///test.txt");
File Filetemp = new File(URItemp);
BufferReader in = new BufferReader(new InputStreamReader(new FileInputStream(Filetemp)));the above cannot work
Error : access denied (java.io.FilePermission \test.txt read)
And then I add
FilePermission fp = new java.io.FilePermission("file:///test.txt", "read");still cannot work
Cound anyone tell me that is possible to do what I want to do?
If yes, how?
Thanks!!

Applets are downloaded from web servers and execute on the client machine.
Therefore they have no access to the web server file system, signed or not.
They could have access to the client file system (the machine where they run),
but for security reasons only signed applets have this privilege.
So to answer your question, you sign if you want to access client files.
To access web server files, you don't need to sign the applet, but you need
to provide some method of accessing files remotely, for instance:
- Files published for the web can be read using HTTP
- Files can be read or writen with the help of an FTP server on the same machine as the web server
- A servlet running on the HTTP server can collaborate with your applet to exchange files

Similar Messages

  • Applet reading files in in web server eg geocities

    hi ,
    i have an applet that reads files i have created in a web server. when i try to run the applet in , internet explorer i get an error message
    java.io.FileNotFoundException: nic.txt (The system cannot find the file specified)
    does anyone have any solution to this problem. do i need a policy file and if i do where do i put it.

    Applets work on the clients computer, not the server. Your applet is >trying to read nic.txt from your computer. Can't be done easily, you'd >need your own serverprogram to do the reading and pass the data to the >client... let me clarify afew points
    the applet is on a webserver eg. geocities.
    the file is also on the same directory as the applet .class file.
    so everything is on the web server,.

  • URGETN HELP NEEDED! JAVA APPLET READING FILE

    Hi everyone
    I need to hand in this assignment today
    Im trying to read from a file and read it onto the screen, my code keeps showing up an error
    'missing method body, or declare abstract'
    This is coming up for the
    public statuc void main(String[] args);
    and the
    public void init();
    Here is my code:
    import java.io.*;
    import java.awt.*;
    import java.applet.*;
    public class Empty_3 extends Applet {
    TextArea ta = new TextArea();
    public static void main(String[] args);
    public void init();
    setLayout(new BorderLayout());
    add(ta, BorderLayout.CENTER);
    try {
    InputStream in =
    getClass().getResourceAsStream("test1.txt");
    InputStreamReader isr =
    new InputStreamReader(in);
    BufferedReader br =
    new BufferedReader(isr);
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    String line;
    while ((line = br.readLine()) != null) {
    pw.println(line);
    ta.setText(sw.toString());
    } catch (IOException io) {
    ta.setText("Ooops");
    Can anyone help me please?
    Is this the best way of doing this? Once i read the file i want to perform a frequency analysis on the words so if there is a better method for this then please let me know!
    Thankyou
    Matt

    Whether it is urgent or not, does not interest us. It might be urgent for you but for nobody else.
    Writing all-capitals is considered shouting and rude.
    // Use code tags for source.

  • Using similiar methods as BufferReader for reading files from web

    Hello!
    I need to read an xml-file in my application. Until now I have used BufferReader-class for that purpose, but the xml-file was located in my hard disk. No I need to get the same file but from the web.
    Can anyone, please, give me some simple example for that? I'll give 10 DD for the good hint. :)
    -- M

    you may find this helpfulBufferedInputStream bis = null;
                        BufferedOutputStream bos = null;
                        try {
                             URL url = new URL(sb.toString());
                             URLConnection urlc = url.openConnection();
                             bis = new BufferedInputStream(urlc.getInputStream());
                             bos = new BufferedOutputStream(new FileOutputStream(destination.getName()));
                             int i;
                             while ((i = bis.read()) != -1) { //read next byte until end of stream
                                  bos.write(i);
                             }//next byte
                        } finally {
                             if (bis != null) try { bis.close(); } catch (IOException ioe) { /* ignore*/ }
                             if (bos != null) try { bos.close(); } catch (IOException ioe) { /* ignore*/ }
                   }//else: input unavailable
            catch (MalformedURLException e) {
                   JOptionPane.showMessageDialog(null,"Internet Failture","Alert ",JOptionPane.PLAIN_MESSAGE);
            catch (IOException ee) {
                   JOptionPane.showMessageDialog(null,"Internet Failture","Alert",JOptionPane.PLAIN_MESSAGE);
            }

  • Applets reading files in their own jar file

    I know there is no way to get my applet to read a file on the hard disk. But
    could I read one that I include in with the .jar file that I create for my applet?
    What about using a Resource type of file? Is this possible?
    Thanks

    Here's a little code stub I used to read a properties file from rt.jar    Properties p = new Properties();
        InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream
         ("java/awt/resources/awt.properties");
        if (is == null) System.out.println("NULL");
        else try { p.load(is); }
        catch (Exception exc) { System.out.println("Exception"); }
        p.list(System.out);You should be able to substitute your path & properties file

  • Applet + Read File??????

    Hello security gurus:
    Could somebody suggest an easy way to read a single xml file from originating on the same sever and directory where the applet resides? People say that an applet can access file from the working directory and all sub-directories this works fine on my system when
    executed directly from the appletviewer or the browser but when I load my program and it's dependencies in a webserver such as tomcat or apache it chokes on applet security exceptions. If someone could help I could stop
    beating my head on the desk where my workstation resides.
    Thanks, Ian

    Hi Bakrudeen,
    I�m a newbie into Java Applets ( so, Java too ), I work with C and C++, but now I need to do somethings using Java. One it�s that I need to do a Applet that read a xml file that�s into my webserver, in the same direcotry that my .class files are. First, I did a java class that run stand alone, it read the file perfectly, after I did a class that extends the applet class, but it didn�t found. Reading your e-mail, I had some questions, than, can you explain better your ideas ? Because, I have the plugins in my machine ( not in the server, the server doesn�t have anything about java, only the Apache server, my webpages and applet classes ), but I can�t read the file ? Another question is: how can I do to see the exceptions messagens to try looking for my errors ?
    See below the source code that I�m trying to use:
    import javax.swing.*;
    import java.awt.*;
    import java.applet.*;
    import java.net.*;
    import java.io.*;
    import org.w3c.dom.Document;
    import org.w3c.dom.*;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.DocumentBuilder;
    import org.xml.sax.SAXException;
    import org.xml.sax.SAXParseException;
    public class WS10Parser extends Applet {
    public int finished;     // 0 - n�o encerrado
    // 1 - encerrado
    // 2 - erro
    private JanelTexto janela;
    public void init() {
    janela = new JanelTexto();
    public void paint(Graphics g) {
    //          g.drawString("Welcome to Java!!", 50, 60 );
    * Fun��o para leitura do arquivo XML
    * Parametros:
    * - Nome do arquivo XML a ser lido
    * - Nome do Dispositivo a ser lido
    * - Modo de leitura do arquivo
    *     - 1 L� somente dados referentes ao dispositivo identificado pelo Nome
    *     - 0     L� informa��es de todos os Devices no arquivo
    //     public void ReadFile(String FileName, String DeviceName, int Mode) {
    public void ReadFile(String FileName) {
    finished = 0;
    URL url;
    try {
    url = new URL(getCodeBase(), FileName);
    janela.AddText("File name: " + url.toString());
    DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
    Document doc = docBuilder.parse(url.openStream());
    // normalize text representation
    doc.getDocumentElement().normalize();
    janela.AddText("Root element of the doc is " + doc.getDocumentElement().getNodeName());
    NodeList listOfDevices = doc.getElementsByTagName("device");
    int totalDevices = listOfDevices.getLength();
    janela.AddText("Total no of devices : " + totalDevices);
    for(int s=0; s<listOfDevices.getLength() ; s++){
    Node firstDeviceNode = listOfDevices.item(s);
    if(firstDeviceNode.getNodeType() == Node.ELEMENT_NODE){
    Element firstDeviceElement = (Element)firstDeviceNode;
    NodeList firstNameList = firstDeviceElement.getElementsByTagName("name");
    Element firstNameElement = (Element)firstNameList.item(0);
    NodeList textFNList = firstNameElement.getChildNodes();
    janela.AddText("Device Name : " + ((Node)textFNList.item(0)).getNodeValue().trim());
    NodeList lastNameList = firstDeviceElement.getElementsByTagName("timestamp");
    Element lastNameElement = (Element)lastNameList.item(0);
    NodeList textLNList = lastNameElement.getChildNodes();
    janela.AddText("TimeStamp : " + ((Node)textLNList.item(0)).getNodeValue().trim());
    NodeList listOfChannels = firstDeviceElement.getElementsByTagName("channel");
    int totalChannels = listOfChannels.getLength();
    janela.AddText("Total no of channels: " + totalChannels);
    for(int cont = 0; cont < listOfChannels.getLength(); cont++) {
    Node channelNode = listOfChannels.item(cont);
    if(channelNode.getNodeType() == Node.ELEMENT_NODE) {
    Element channelElement = (Element)channelNode;
    NodeList tagList = channelElement.getElementsByTagName("tag");
    Element tagElement = (Element)tagList.item(0);
    NodeList textTagList = tagElement.getChildNodes();
    janela.AddText("Tag: " + ((Node)textTagList.item(0)).getNodeValue().trim());
    NodeList valueList = channelElement.getElementsByTagName("value");
    Element valueElement = (Element)valueList.item(0);
    NodeList textValueList = valueElement.getChildNodes();
    janela.AddText("Value: " + ((Node)textValueList.item(0)).getNodeValue().trim());
    }//end of if clause
    }//end of for loop with s var
    finished = 1;
    }catch (SAXParseException err) {
    janela.AddText("** Parsing error" + ", line " + err.getLineNumber() + ", uri " + err.getSystemId());
    janela.AddText(" " + err.getMessage());
    finished = 2;
    }catch (SAXException e) {
    Exception x = e.getException();
    ((x == null) ? e : x).printStackTrace();
    finished = 3;
    }catch (Throwable t) {
    t.printStackTrace();
    finished = 4;
    private class JanelTexto extends JFrame {
    private JTextArea ta;
    public JanelTexto() {
    super("Teste Applet Novus");
    Box b = Box.createHorizontalBox();
    ta = new JTextArea(20, 30);
    b.add(new JScrollPane(ta));
    Container c = getContentPane();
    c.add(b);
    setSize(425, 200);
    show();
    public void AddText(String Text) {
    ta.append(Text + '\n');
    Thanks

  • How do I make an Applet read a file on my web host?

    How do I make an Applet read a file on my web host?
    I am wanting to put a file on my web host that has usernames and user details and other stuff on it...
    I was wondering whether anyone knows how to make the Applet open a file on my webserver, check if the username exists, if not add to the file the username and details?
    thanks

    URL myURL = new URL(getDocumentBase(), filename);
    InputStream myInputStream = myURL.openStream();
    DataInputStream dis = new DataInputStream(myInputStream);
    String oneLine = dis.readLine();
    Use output stream for writing..
    hope this works !!!

  • Applet can't read local file on web server, security issue!

    There is any way to read/write files of web server through the applet except the Signed Applet.
    If any idea the reply me soon.
    Thanks in advance

    Applets are downloaded from web servers and execute on the client machine.
    Therefore they have no access to the web server file system, signed or not.
    They could have access to the client file system (the machine where they run),
    but for security reasons only signed applets have this privilege.
    So to answer your question, you sign if you want to access client files.
    To access web server files, you don't need to sign the applet, but you need
    to provide some method of accessing files remotely, for instance:
    - Files published for the web can be read using HTTP
    - Files can be read or writen with the help of an FTP server on the same machine as the web server
    - A servlet running on the HTTP server can collaborate with your applet to exchange files

  • Reading file in Applet.

    Hello All,
    i am trying to read a file in applet. i have created a applet that reads file and prints its content. it works fine on local system but when i publish this applet in web server it gives such exceptions.
    java.security.PrivilegedActionException: java.lang.reflect.InvocationTargetException
         at java.security.AccessController.doPrivileged(Native Method)
         at sun.plugin.liveconnect.SecureInvocation$2.run(Unknown Source)
         at java.security.AccessController.doPrivileged(Native Method)
         at sun.plugin.liveconnect.SecureInvocation.CallMethod(Unknown Source)
    Caused by: java.lang.reflect.InvocationTargetException
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
         at java.lang.reflect.Method.invoke(Unknown Source)
         at sun.plugin.javascript.JSInvoke.invoke(Unknown Source)
         at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
         at java.lang.reflect.Method.invoke(Unknown Source)
         at sun.plugin.javascript.JSClassLoader.invoke(Unknown Source)
         at sun.plugin.liveconnect.PrivilegedCallMethodAction.run(Unknown Source)
         ... 4 more
    Caused by: java.security.AccessControlException: access denied (java.io.FilePermission C:\reading\run.bat read)
         at java.security.AccessControlContext.checkPermission(Unknown Source)
         at java.security.AccessController.checkPermission(Unknown Source)
         at java.lang.SecurityManager.checkPermission(Unknown Source)
         at java.lang.SecurityManager.checkRead(Unknown Source)
         at java.io.FileInputStream.<init>(Unknown Source)
         at readFile.showContent(readFile.java:38)
    Can some body say whats going on?
    I am stuck over here.
    Any help will be appreciated.
    Regards
    Jaya N pasachhe.

    If you are surfing the web, and you click a link to a page that you don't know, you don't want some unknown Applet to start and be allowed access to your local harddrive or printer.
    Therefore, Applets ran by the browser, run in a so-called "sandbox". Read about it.
    The solution is to "sign" the applet's jar.
    see http://www-personal.umich.edu/~lsiden/tutorials/signed-applet/signed-applet.html
    and http://forum.java.sun.com/thread.jspa?threadID=174214

  • Applet read/write files

    Hi,
    I have a problem to use getCodeBase to get the URL. Actually, I am pretty confused on running the applet in our intranet.
    Let me explain my problem here, I have mapped a network drive(G:\personA) in my machine and my applet and all the files are in G:\personA\classes. In my coding, I have tried to specify my files paths such as G:\personA\classes\index.txt and I can run the applet without any problem either with Eclipse or from a web site http://personA//report.html. But the other members in this company cannot run this applet thro' this web site( http://personA//report.html). The problem is "No class found", can't find the path G:\personA\classes\index.txt.
    So I decided to change my code by reading/writing files thro URL i,e : http://personA/classes, but when I run my applet, I got the following exception :
    ava.lang.NullPointerException
         at java.applet.Applet.getCodeBase(Applet.java:136)
         at web.MyChart.readAndPrintData(MyChart.java:336)
         at web.MyChart<init>(MyChart.java:113)
         at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
         at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
         at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
         at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
         at java.lang.Class.newInstance0(Class.java:308)
         at java.lang.Class.newInstance(Class.java:261)
         at sun.applet.AppletPanel.createApplet(AppletPanel.java:617)
         at sun.applet.AppletPanel.runLoader(AppletPanel.java:546)
         at sun.applet.AppletPanel.run(AppletPanel.java:298)
         at java.lang.Thread.run(Thread.java:534)
    does anybody knows how to solve this problem?? Please...
    Thanks,
    Tiffany

    I think a trace would help, guessing is fun but won't solve your problem:
    To turn the full trace on (windows) you can start the java console, to be found here:
    C:\Program Files\Java\j2re1.4...\bin\jpicpl32.exe
    In the advanced tab you can fill in something for runtime parameters fill in this:
    -Djavaplugin.trace=true -Djavaplugin.trace.option=basic|net|security|ext|liveconnect
    if you cannot start the java console check here:
    C:\Documents and Settings\userName\Application Data\Sun\Java\Deployment\deployment.properties
    I think for linux this is somewhere in youruserdir/java (hidden directory)
    add or change the following line:
    javaplugin.jre.params=-Djavaplugin.trace\=true -Djavaplugin.trace.option\=basic|net|security|ext|liveconnect
    for 1.5:
    deployment.javapi.jre.1.5.0.args=-Djavaplugin.trace\=true -Djavaplugin.trace.option\=basic|net|security|ext|liveconnect
    The trace is here:
    C:\Documents and Settings\your user\Application Data\Sun\Java\Deployment\log\plugin...log
    I think for linux this is somewhere in youruserdir/java (hidden directory)

  • Writing applets that read files hosted on a webserver.

    I have a java applet that I need to be able to read files on the webserver. IE open and render images. I know ultimately the user will end up downloading these images that are hosted on the websserver, but the java applet is set to read from it's local directory, for example, when I open up a text files, I use the path someFolder\someFile.txt. If the applet was placed in the same folder as someFolder on the webserver, how would I set it up to read from there opposed to on the machine executing the java code? Would I have to force the user to download all the resources, in thus case, wouldn't I need to to have the applet signed?

    ++++ to everything by malcolmmc (use class.getResource())
    Jeremy.W wrote:
    ...I could perform a CRC check and compare the archives with the ones on the server, but it still means I'd need to compress the archives manually every time an update is made to the files on the server.I am not sure whether you are concerned with the effort of doing this from your side. If so, use Ant to make your ..war file or whatever and just upload it (and restart the server?).
    If it is the archives (Jar or Zip) updating on the client that is your major concern, then I would definitely recommend the JNLP based option, which gives the client not only automatic update (the JWS client manages the time checks with the server), but if you want to go that far, direct programmatic access to the download API. I made a crude example (never properly finished) of downloading resources using the JNLP APIs DownloadService. (Though the standard 'auto-update' is known to be quite effective).
    Oh, and.. Of course, if you have a Java enabled server, the download servlet is known to be best for updates, incremental or otherwise.
    Does this applet really need to be embedded in a web page at all? JWS has offered these things to free-floating applets since Java 1.2, it is only recently an embedded applet could hook into the JNLP API.
    As to the 'Zip' archives of resources. Some points:
    1) It pays to split them up, especially if resources are likely to change frequently in one, but rarely for others. If you do that, webstart ensures the user only downloads the updated Jars. The only way to achieve a class/resource refresh in a conventional embedded applet ('plugin1') was to flush the class cache which would force refresh of all classes/resources.
    2) Splitting the archives according to type of resource can provide benefits in that the Jars can have different compression levels appropriate to the format.
    3) I would recommend deploying all resources, whether classes or other resources, in Jar and not Zip files. Sun has decided that no Zip will be checked to see if it is digitally signed, so Zip archives can cause problems for apps. which might need extended permissions (if it ever comes to that).

  • AdobeAcrobat/Reader that is running can not be used to view PDF Files in Web Browser...what do I need to do to fix this..

    I just got Windows 7 and have been having problems since loading it. Most of my drivers only go to Vista and don't recognize 7.
    I have trying to download some manuals from their website
    and keep getting this message; Adobe Acrobat/reader that is running can not be used to view PDF files in Web Browser.

    Could I suggest a workaround for PDFs until a solution is posted? Open them directly in the Adobe application rather than in a browser tab.
    In your Adobe application(s), go to:
    Edit > Preferences > Internet
    Then uncheck "Display PDF in browser"
    (There are very few sites where having PDF integrated is really beneficial.)

  • How do I read a properties file in WEB-INF without hard-coding a path?

    Hello,
    How do I read a properties file in WEB-INF without hard-coding a path?
    I tried:
    Properties properties = new Properties();
    properties.load(new FileInputStream("db.properties"));
    driver = properties.getProperty("driver");
    but it cannot find the db.properties file.
    Thanks for the help.
    Frank

    Don't use a File to read those properties.
    Better to use the servlet context and
    getResourceAsStream() method to get the InputStream.
    It'll look for any file in the CLASSPATH. If you put
    that properties file in the WEB-INF/classes directory
    you'll have no problems, even if you deploy with a
    WAR file.Completely agree with this approach. Just have to mention the following for completeness
    according to the API,
    "This method is different from java.lang.Class.getResourceAsStream, which uses a class loader. This method allows servlet containers to make a resource available to a servlet from any location, without using a class loader. "
    So using this method, the resource can be anywhere under your web context, not just in the classpath.
    Cheers,
    evnafets

  • Reading contents of uploaded excel file in web dynpro java

    Hi All.
    I am aware how to provide facility to upload files in web dynpro java. But my requirement is that on uploading a particular file (for eg. an excel file having 10 columns), I need to read the contents of that file and store it in a table in R/3.Can anyone suggest a way how I can read the contents of the uploaded file?
    Thanks and Regards,
    Saurabh.

    Hi.
    I am having the following requirement : I have a FileUpload UI element where user clicks Browse button, selects a file from the local system and presses a Upload button. Upon pressing Upload, the name of the selected file and the contents of the file should be shown.
    In the View context, I have two value attributes: FileName of type String and FileResource of type binary.
    This is the code that I have in the Upload button action handler :
      public void onActionUpload(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
        //@@begin onActionUpload(ServerEvent)
        IWDAttributeInfo attributeInfo = wdContext.getNodeInfo().getAttribute(
                 IPrivateReadExcelView.IContextElement.FILE_RESOURCE);
        IWDModifiableBinaryType binaryType = (IWDModifiableBinaryType)attributeInfo.
                 getModifiableSimpleType();
        IPrivateReadExcelView.IContextElement element = wdContext.createContextElement();
        String fname = binaryType.getFileName();
        wdComponentAPI.getMessageManager().reportSuccess("File selected - "+fname);  //Statement 1
         try {
              wdComponentAPI.getMessageManager().reportSuccess("Successful");    // Statement 2
              InputStream in = new FileInputStream(fname);
              HSSFWorkbook wb = new HSSFWorkbook(in);
              wdComponentAPI.getMessageManager().reportSuccess("Successful");    //Statement 3
              int sheetsNo = wb.getNumberOfSheets();
              for (int i=0;i<sheetsNo;i++) {
                   HSSFSheet sheet = wb.getSheetAt(i);
                   Iterator rowsNo = sheet.rowIterator();
                   while(rowsNo.hasNext()) {
                        HSSFRow rows = (HSSFRow)rowsNo.next();
                        Iterator colsNo = rows.cellIterator();
                        while(colsNo.hasNext()) {
                             HSSFCell cell = (HSSFCell)colsNo.next();
                             wdComponentAPI.getMessageManager().reportSuccess("File uploaded" +
                                  "successfully");
                             if(cell.getCellType()==1) {
                                  wdComponentAPI.getMessageManager().reportSuccess("00000"+
                                       cell.getStringCellValue());
                             else if(cell.getCellType()==0) {
                                  String str=""+cell.getNumericCellValue();
                                  wdComponentAPI.getMessageManager().reportSuccess("11111"+str);
         catch(Exception e) { wdComponentAPI.getMessageManager().raisePendingException();
        //@@end
    On pressing Upload button, name of selected file is being shown(Statement 1). I am also getting Statement 2 in the output. However I am not getting Statement 3 onwards.
    Where am I going wrong? Can anyone shed some light on this?

  • Why do I receive this message? The Adobe Acrobat Reader that is running cannot be used to view PDF files in a browser. Please exit Adobe Acrobat Reader and your web browser and try again.

    The Adobe Acrobat Reader that is running cannot be used to view PDF files in a browser. Please exit Adobe Acrobat Reader and your web browser and try again.
    == This happened ==
    A few times a week
    == Early this year

    See these KB articles:
    https://support.mozilla.com/en-US/kb/Using+the+Adobe+Reader+plugin+with+Firefox
    https://support.mozilla.com/en-US/kb/Opening+PDF+files+within+Firefox

Maybe you are looking for