Need signed applet to read a file in the jar?

i have an applet and i need to read a file (just a picture .jpg) within the jar. but i got a security exception when i try to make the File object for this jpg
thanks and sorry for my english

Image image = Toolkit.getDefaultToolkit().getImage(getClass().getResorce("FileName.jpg"));i need to make something like this
File file = new File("picture.jpg");
the idea is verify that picture.jpg is really the picture that i put and not other with the same name... and if it is a file objet i can see the last modification date, to make a validation...
another way is to read some pixels and verify that its colors dont change... but i dont know how to do this neither.
but thanks anyway!

Similar Messages

  • How to read, write file inside the JAR file?

    Hi all,
    I want to read the file inside the jar file, use following method:
    File file = new File("filename");
    It works if not in JAR file, but it doesn't work if it's in a JAR file.
    I found someone had the same problem, but no reply.
    http://forum.java.sun.com/thread.jsp?forum=22&thread=180618
    Can you help me ? I have tried this for all night !
    Thanks in advance
    Leo

    If you want to read a file from the JAR file that the
    application is packaged in (rather than a separate
    external JAR file) you do it like this ...
    InputStream is =
    ClassLoader.getSystemResourceAsStream("filename");Better to use
    this.getClass().getClassLoader().getResourceAsStream();
    From a class near to where the data is. This deals with multiple classloaders properly.

  • How to read some files inside the jar

    Hi,
    I have an applet that runs with JWS. The user can input some information and then I need to show this information in a web page. As the application can be run offline, I cannnot use JSP�s to generate the web page. The information is saved in a xml file, so I use a xsl parser to generate the html code. The problem is that I have to include some javascript files (.js). I put these files inside the jar, but, how can I read these files, or how can I reference these files from inside the html page ?
    Thanks !

    You can use getClass().getResource(classpath)
    to get a stream version of the data from your
    jar file. If you need to put it in a file, you
    can write that stream to a file in a temp directory.
    classpath is the classpath of your js file

  • How to read a file inside the JAR file

    Hi All,
    I want to save some preferences in a file called "preferences". I kept the preferences file under my java package.
    If i am running the code inside the NetBeans 6.9 IDE it's working file. But once i have created a JAR and try to run the application, it couldn't find the path.
    Please help me that how to resolve this issue. I don't want to save this preferences file outside of my JAR (i.e) within my java package.
    Here is the code,
    package mypackage;
    import java.io.BufferedReader;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.InputStreamReader;
    import java.io.OutputStream;
    import java.io.PrintWriter;
    public class ReadFile
        private void writeFile()
            try
                OutputStream out = new FileOutputStream(getClass().getClassLoader().getResource("mypackage/preferences").getPath().replace("%20", " "));
                PrintWriter writer = new PrintWriter(out);
                writer.println("Hello Java!");
                writer.close();
                out.close();
            catch (Exception ex)
                System.out.println(ex.getMessage());
        private void readFile()
            try
                FileInputStream fi = new FileInputStream(getClass().getClassLoader().getResource("mypackage/preferences").getPath().replace("%20", " "));
                BufferedReader br = new BufferedReader(new InputStreamReader(fi));
                System.out.println(br.readLine().trim());
                br.close();
                fi.close();
            catch (Exception ex)
                System.out.println(ex.getMessage());
        public static void main(String[] args)
            ReadFile read = new ReadFile();
            read.writeFile();
            read.readFile();
    }If i run the JAR, i get the following error message,
    {color:#ff0000}*file:\my jar path\jarname.jar!\mypackage\preferences (The filename, directoryname, or volume label syntax is incorrect)*{color}

    Thanks sabre150,
    sabre150 wrote:
    You cannot update a running jar file. I am sorry. I didn't know about it. Thanks to point out.
    There are two ways I approach this depending on my exact requirements -
    1) use the java.util.prefs.Preferences APII will try this one
    >
    2) if not already present I copy the preferences file from the jar to a known place. I use a directory in the user's home directory and normally make the directory name the program with a '.' prefix.
    One cannot access files in a jar file using the File API. One needs to use the getResource() or getResourceAsStream() methods on Class or ClassLoader.

  • Reading a file in the JAR

    i have a jar with class files and xml files in it. my application uses this jar and a particular class has a link to the xml. but while compiling, it shows path not found. the application couldnt read the xml file in the jar. how to set the path or read the xml file
    XML file in JAR:
    SQLMaps/admin/sample.xml [folder structure inside the jar file]
    my application has a path like SQLMaps/admin/sample.xml
    but how do we point to the xml file in the jar
    Regards
    Pradheep

    thanks anyway
    but i need the application to read the xml file in the jar file
    to be more clear.
    the jar file has xml in a specified folder.

  • I need a help in reading video file of 80MB into ...

    Hello,
    I need a help in reading video file of 80MB into a vector storing ByteArrays in it.Please help me soon.
    Thank You

    Hello,
    I was able to solve my problem by thinking & my code goes as follows.I am trying to read a video file in my program.
    public Vector getFileMediaContent(RandomAccessFile fileObj){
         Runtime runtime = Runtime.getRuntime();
    System.out.println ("Free memory : inside Boolean Type Panel" + runtime.freeMemory() );
    dataContent.removeAllElements();
    System.out.println("dataContent :"+dataContent.size());
    try{
    int size=(int)fileObj.length();
    if(size<2000000){
    byte[] data = new byte[size];
    fileObj.read(data);
    dataContent.addElement(data);
    data=null;
    System.gc();
    else{
    int fixedsize=2000000;
    int startindex=0;
    int read=0;
    int remaining=0;
    while(read!=-1){
    byte[] data=new byte[fixedsize];
    read=fileObj.read(data,0,data.length);
    dataContent.addElement(data);
    startindex=startindex+data.length;
    remaining=size-startindex;
    fileObj.seek(startindex);
    data=null;
    System.gc();
    if(remaining>0 && remaining<2000000){
    byte[] data1=new byte[remaining];
    read=fileObj.read(data1,0,data1.length);
    dataContent.addElement(data1);
    data1=null;
    System.gc();
    System.out.println("outside while");
    System.out.println("dataContent 1 :"+dataContent.size());
    System.out.println ("Free memory : inside Boolean Type Panel" + runtime.freeMemory() );
    fileObj = null;
    System.gc();
    }catch(Exception e){
    e.printStackTrace();
    return dataContent;
    Now I am not facing the problem of IndexOut of Bounds Exception But I am getting Out of Memory Error.
    Can You suggest me to come out of this,.
    As I know I have two solutions.
    1.Make the objects Null which is using more space & call System.gc();
    2.Increase the Virtual Memory of my System.
    Any solutions other than this?
    And How to Increase the Virtual Memory?Please do reply.
    ThankYou

  • I want to read a file on the client side

    Hi all,
    I want to read a file on the client side, then the server show the contents of that file.

    Signed applet sounds cool - I guess Microsoft's ActiveX technology would be the mirror of this.
    Write you file access code as you normally would and then just drop it in a applet and JAR it up.
    Use keytool to sign it - users will be requested to accept/review your certificate in order to grant file-access permissions.
    Warm regards.

  • I can't read a file with the ext PDF the sender informed me that the file was reset to PDF.

    I can't read a file with the .ext PDF the sender informed me that the file was reset to PDF. But when I tried to open it the caption box informed me"the file is not in PDF format. I suspect the sender simply changed the file .ext which is why I can't open it! What can I do about it! I am working on an iPad.
    Thanks
    Mr Jim Lapthorn

    If the document is not, in fact, a PDF, then you will need to get your sender to provide a PDF.
    Can you open this document in any other application?

  • How to read a file outside my .jar

    Hello!
    I have my j2me application in a .jar file , and my application needs to read a .txt file which is outside my .jar but in the same directory.
    I tried to do :
    InputStream input = getClass().getResourceAsStream("/myfile.txt");
    as well as
    InputStream input = getClass().getResourceAsStream("myfile.txt");
    but nothing is working...
    Could you help me, please??? I'm getting crazy with this :(
    Thanks in advance!

    Thanks sabre150,
    sabre150 wrote:
    You cannot update a running jar file. I am sorry. I didn't know about it. Thanks to point out.
    There are two ways I approach this depending on my exact requirements -
    1) use the java.util.prefs.Preferences APII will try this one
    >
    2) if not already present I copy the preferences file from the jar to a known place. I use a directory in the user's home directory and normally make the directory name the program with a '.' prefix.
    One cannot access files in a jar file using the File API. One needs to use the getResource() or getResourceAsStream() methods on Class or ClassLoader.

  • How to read files outside the jar ?

    Hi all,
    One of my classes inside jar needs to read XML file that resides in the same location where the jar sits. I use MyClass.getClass().getResource("MyXMLFile.xml") but it keeps returning null.
    If I place the XML file inside the JAR, I can find it using above methods, but since I want the user to easily edit the XML file without opening the jar file and detach the XML file, I choose not to include the XML file inside the jar.
    Any help would be greatly appreciated.
    Setya

    Thanks for the dukes.
    My JDBC post on this forum discusses the issues of
    using Class-Path in your jar file. It works, but it
    may vary from system to system.
    Thanks also from my side: I have read recently your discussion about reading files in the jar's directory, since I had the same problem. So I was really glad to see your solution. However, I had one more problem, namely that I'm running my application sometimes from the jar, sometimes from the classes directly (debugging). In order to have always the correct path (although a different one) I have added some more lines to deal with that case. I hope that will be useful for you as well!
    Dieter Profos
    import java.awt.*;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import java.awt.event.WindowListener;
    import java.net.URL;
    * @author pkwooster
    * @author Dieter Profos
    * @version 1.01 04/03/26
    public class ReadOutside extends Frame {
    private TextArea textArea;
    public static void main(String[] args) {
    // Create application frame.
    ReadOutside tc = new ReadOutside();
    tc.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent we) {
    System.exit(0);
    // Show frame
    tc.setSize(600,250);
    tc.setVisible(true);
    public ReadOutside() {
    textArea = new TextArea(20,80);
    add(textArea);
    readOutside(this);
    public void readOutside(Object o) {
    System.out.println(getCodeBasePath(o));
    /** Gets the absolute path of the directory where the JAR or CLASS file is
    * located. If the application is run from a jar file, the directory of the
    * jar file is returned; if it is run from a class file, the method will
    * return the directory path of the class file.
    * @param o The main class of the application.
    * @return The absolute directory path, or null if neither the class nor a
    * jar file could be found.
    public String getCodeBasePath(Object o) {
    Class c = o.getClass();
    URL url;
    // get the class name
    String className = c.getName();
    textArea.append("class name = " + className + "\n");
    // replace package periods by file separators
    className = className.replace('.','/');
    ClassLoader cl = c.getClassLoader();
    if (cl == null)
    cl = ClassLoader.getSystemClassLoader();
    url = cl.getResource(className + ".class");
    String xPath = url.toExternalForm();
    textArea.append("url = " + url + "\n");
    textArea.append("extPath = " + xPath + "\n");
    // make sure that the path starts with jar:file:
    if (xPath.startsWith("jar:file:")) {
    // remove jar:file: + the subsequent file separator
    xPath = xPath.substring("jar:file:".length()+1);
    int n = xPath.indexOf("!");
    if (n < 0)
    n = xPath.length();
    String jarPath = xPath.substring(0, n);
    textArea.append("jar file path = " + jarPath + "\n");
    n = jarPath.lastIndexOf("/");
    String jarDir = jarPath.substring(0, n+1);
    textArea.append("jar dir = " + jarDir + "\n");
    return jarDir;
    else { // if program is run from its class file (development phase!)
    if (xPath.startsWith("file:")) {
    // remove file: + the subsequent file separator
    xPath = xPath.substring("file:".length()+1);
    textArea.append("class file path = " + xPath + "\n");
    int n = xPath.lastIndexOf("/");
    String classDir = xPath.substring(0, n+1);
    textArea.append("class dir = " + classDir + "\n");
    return classDir;
    return null;

  • How do I read PDF files from the SARS website

    How do I read PDF files from the SARS website
    Got the latest version xi.0.08 of Abobe Reader
    Operating system is win XP Sp3

    You need Adobe Reader or Adobe Acrobat or other PDF reading application installed on your system. Then just double click on the form or publication wanted and follow the prompts as needed.

  • Reading trace file on the fly.

    I came across one cool trick mentioned by Tanel Poder, but it doesn't seem to work for me. Could anyone please help in reading trace file on the fly.
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
    With the Partitioning, Real Application Clusters, OLAP, Data Mining
    and Real Application Testing options
    SQL> !uname -a
    Linux abc 2.6.16.60-0.34-smp #1 SMP Fri Jan 16 14:59:01 UTC 2009 x86_64 x86_64 x86_64 GNU/Linux
    SQL> select value ||'/'||(select instance_name from v$instance) ||'_ora_'||
      2             (select spid||case when traceid is not null then '_'||traceid else null end
                     from v$process where addr = (select paddr from v$session
      3    4                                               where sid = (select sid from v$mystat
      5                                                          where rownum = 1
      6                                                     )
      7                                          )
      8             ) || '.trc' tracefile
      9      from v$parameter where name = 'user_dump_dest'
    10     /
    TRACEFILE
    /n01/oraadmin1/diag/rdbms/abc/inst1/trace/inst11_ora_28754.trc
    SQL> host mknod /n01/oraadmin1/diag/rdbms/abc/inst1/trace/inst11_ora_28754.trc p
    SQL> set define off
    SQL> host grep "WAIT" /n01/oraadmin1/diag/rdbms/abc/inst1/trace/inst11_ora_28754.trc &
    SQL> set define on
    SQL> alter session set events '10046 trace name context forever, level 8';
    Session altered.
    SQL> select * from dual;
    D
    X
    SQL>
    SQL> select * from dual;
    D
    X
    {code}
    I dont get any WAIT printed into the pipe file created before tracing.
    Am i doing something wrong here ?
    Edited by: Yasu on Nov 12, 2012 10:14 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    I tried manual method and yes i am able to find WAIT lines in trace file.
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
    With the Partitioning, Real Application Clusters, OLAP, Data Mining
    and Real Application Testing options
    SQL> select value ||'/'||(select instance_name from v$instance) ||'_ora_'||
               (select spid||case when traceid is not null then '_'||traceid else null end
      2    3                   from v$process where addr = (select paddr from v$session
      4                                               where sid = (select sid from v$mystat
      5                                                          where rownum = 1
      6                                                     )
      7                                          )
      8             ) || '.trc' tracefile
      9      from v$parameter where name = 'user_dump_dest'
    10     /
    TRACEFILE
    /n01/oraadmin1/diag/rdbms/proddba/proddba1/trace/proddba1_ora_23021.trc
    SQL> alter session set events '10046 trace name context forever, level 8';
    Session altered.
    SQL> select * from dual;
    D
    X
    SQL> alter session set events '10046 trace name context off';
    Session altered.
    SQL> !ls -lrt /n01/oraadmin1/diag/rdbms/proddba/proddba1/trace/proddba1_ora_23021.trc
    -rw-r----- 1 oracle oinstall 2738 2012-11-12 01:13 /n01/oraadmin1/diag/rdbms/proddba/proddba1/trace/proddba1_ora_23021.trc
    SQL> !grep "WAIT" /n01/oraadmin1/diag/rdbms/proddba/proddba1/trace/proddba1_ora_23021.trc
    WAIT #1: nam='SQL*Net message to client' ela= 6 driver id=1650815232 #bytes=1 p3=0 obj#=-1 tim=1352704368368424
    WAIT #1: nam='SQL*Net message from client' ela= 4057810 driver id=1650815232 #bytes=1 p3=0 obj#=-1 tim=1352704372428142
    WAIT #1: nam='SQL*Net message to client' ela= 6 driver id=1650815232 #bytes=1 p3=0 obj#=-1 tim=1352704372428492
    WAIT #1: nam='SQL*Net message from client' ela= 195 driver id=1650815232 #bytes=1 p3=0 obj#=-1 tim=1352704372428892
    WAIT #1: nam='SQL*Net message to client' ela= 3 driver id=1650815232 #bytes=1 p3=0 obj#=-1 tim=1352704372428939
    WAIT #1: nam='SQL*Net message from client' ela= 46319788 driver id=1650815232 #bytes=1 p3=0 obj#=-1 tim=1352704418748740Not sure why using mknod fails in my case.
    Edited by: Yasu on Nov 12, 2012 12:48 PM

  • I have a problem with the mac can not read video files with the extension IMOD. How can I solve this problem?

    I have a problem with the mac can not read video files with the extension IMOD. How can I solve this problem?

    By doing a Google search. 

  • Java Files inside the jar file cannot be read or accessed through Eclpse

    The Java File inside the jar file of the eclipse cannot be accessed through the Eclipse . It shows error for the modules in the jar file .
    But when compiled with adding the jar files to the class path the compilation is successful .
    How can i browse through the files in the jar like going into the function definition .
    TIA ,
    Imran

    Open MPlayer OSX and show the playlist (command-shift-p) then drag the file into the playlist. Click the file in the playlist and click the "i"nfo button. What does it list for file, video and audio format?
    Not all of the codecs used in avi and wmv files are available for OS X so I'm guessing your file happens to be using one that isn't...

  • Is it possible to read Prezi files within the iOS app?

    Hello,
    I want to implement Prezi into my iOS app. I am totally unaware that "Is it possible to read Prezi files within the iOS app?".
    If Yes, please provide some tutorial link, so that I can implement into my application.
    Thanks & regard.

    You will get a better answer in
    Developer Forums
    Use your Developer credentials to log in there.

Maybe you are looking for

  • BED Rate in Excise Invoice and ARE-3

    Hello All, I am having a problem in excise invoice and Creation of ARE-3. The system is calculating the Excise components (BED/ECS/Higher Cess) but when i check the table J_1IEXCDTL, it is displaying the values but not the %age rates. The same proble

  • How do I fill a 40GB iPod with random subset of a larger music library?

    I have more songs than will fit on my 40GB ipod. I would like to have a random subset of my library uploaded to fill my ipod. And then next time, I want to replace all the songs on my ipod with another random subset of my library. I believe there is

  • Making portal services as web services

    hi,       i have created a portal service. i want to publish this as web service . anyone know how to do this ... padma

  • Impact due to change in COA structure (removal of project segment)

    Hi, We are implementing PA for a client. Their existing COA has projects as an accounting segment. Currently they consider "00000"(Default Project segment value) as operating project. So at any time the sum of balance of all the account combination h

  • Disabling Digital Signatures

    Hi, Can anyone give me some solid evidence that disabling digital signatures on our 2003 network (for our 10 mac users) would be a good alternative? Right now we have 125 PC's and 10 Mac computers on our network using Active Directory. I have also se