How to check file exist in applet?

I would like to check the existance of a file from an applet. How can I achieve that? I'd tried many attempts but still fail to get an answer. Please kindly help.
Below are my file structures:-
folder/applet/myApplet.java
folder/appletView.jsp
folder/image/image1.gif
I would like to check if image1.gif exist. if yes, then load and display it in applet, but I having problem on the how to specify the file location.

Assuming image1 is in the same folder as the applet:
          InputStream is;
          byte[] buf = new byte[1024];
          URLConnection urlc = null;
          try {
               URL a = new URL(this.getCodeBase(),"image1.gif");
               urlc = a.openConnection();
               is = urlc.getInputStream();
               int len = 0;
               ByteArrayOutputStream bos = new ByteArrayOutputStream();
               while ((len = is.read(buf)) > 0) {
                    bos.write(buf, 0, len);
               // close the inputstream
               is.close();
          } catch (IOException e) {
               try {
// image1.gif probably does not exist
                    // now failing to read the inputstream does not mean the server did not send
                    // any data, here is how you can read that data, this is needed for the same
                    // reason mentioned above.
                    ((HttpURLConnection) urlc).getResponseCode();
                    InputStream es = ((HttpURLConnection) urlc).getErrorStream();
                    int ret = 0;
                    // read the response body
                    while ((ret = es.read(buf)) > 0) {
                    // close the errorstream
                    es.close();
               } catch (IOException ex) {
                    // deal with the exception
          }

Similar Messages

  • How to check File size of a Text file.

    How to check File size of a Text file.
    please explain me.
    I am new in LabVIEW. and dont have much idea on this...;
    Prashant Soni
    LabVIEW Engineer
    Solved!
    Go to Solution.

    Hi Prashant,
    and here's what you get when using the LV help...
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • How to check file is exists  in specified path in content server or not

    i m using JDevloper 11.1.1.6.0
    I want to upload file using RIDC functions,but before uploading it i have to check wheather it is already present on specified path in content server or not.
    How i check it.

    I tried to write a (simpler) version of my own code:
        public static Results CheckInToFolder(File f) {
            // create the binder
            DataBinder checkinDoc = idcClient.createBinder();
            // populate the binder with the parameters
            checkinDoc.putLocal("IdcService", "CHECKIN_UNIVERSAL");
            checkinDoc.putLocal("dDocTitle",
                                "Document checked in through RIDC at " +
                                new Date());
            checkinDoc.putLocal("dDocType", "Document");
            checkinDoc.putLocal("dDocAccount", "");
            checkinDoc.putLocal("dSecurityGroup", "Public");
            checkinDoc.putLocal("dCollectionID", "909964822906001607");
            // add a file
            // execute the request
            try {
                checkinDoc.addFile("primaryFile", f);
            } catch (IOException e) {
                myExecutable.logEvent("File" + f.getName() + " not found.");
                return null;
            ServiceResponse checkinResponse;
            try {
                checkinResponse = idcClient.sendRequest(userContext, checkinDoc);
                myExecutable.logEvent("Check-in successful. Size:" + f.length() + " bytes");
            catch (oracle.stellent.ridc.protocol.ServiceException e) {
                            myExecutable.logEvent("ServiceException");
                            e.printStackTrace();
                            return null;   
            catch (IdcClientException e) {
                myExecutable.logEvent("Check-in failed.");
                e.printStackTrace();
                return null;
            DataBinder checkinData;
            try {
                checkinData = checkinResponse.getResponseAsBinder();
                Results res =
                    new Results(checkinData.getLocal("dID"), checkinData.getLocal("dDocName"));
                myExecutable.logEvent("Successfully got response - dID is " +
                                      res.getDID() + ", dDocName is " +
                                      res.getDDocName());
                return res;
            catch (oracle.stellent.ridc.protocol.ServiceException e) {
                            myExecutable.logEvent("ServiceException2");
                            //e.printStackTrace();
                            return null;   
            catch (IdcClientException e) {
                myExecutable.logEvent("Unable to get response.");
                e.printStackTrace();
            return null;
        }What I'm getting is this:
    Mon Aug 13 14:51:29 CEST 2012 0ms: Started
    Mon Aug 13 14:51:29 CEST 2012 57ms: Connection to idc://192.168.44.129:4444 successfully established.
    Mon Aug 13 14:51:29 CEST 2012 102ms: Check-in successful. Size:702 bytes
    Mon Aug 13 14:51:29 CEST 2012 5ms: ServiceException2
    Mon Aug 13 14:51:29 CEST 2012 0ms: Finished
    This means:
    a) it does, indeed, return the exception (oracle.stellent.ridc.protocol.ServiceException)
    b) you could use this mechanism for your code
    c) it is, indeed, primaryFile.name what's being checked
    I will also take a look at the other service to perform the check prior to check-in service call.

  • Checking file exist using file exist operator

    Hi all,
    My environment is owb 9i. DB is oracle 9.2.0.8
    My business requirement is,
    If file exists in the landing directory the next instant my mapping should start execution other wise it should wait untill the file arrives there.
    How could i achive this functionality???
    For this i am utilizing the file exist operator in process flow.
    When the file exists in the specified directory i am able to execute the process flow quite fine but when the file doesnt exist in the specified directory the file exist operator is in wait state and even after when the file is placed into the directory, still the process flow remains in the wait state.
    please suggest me a way.
    thanks in advance.
    ram.

    Hi Ram,
    The problem you are hitting here is that there is no wait activity and no loop activity (yet) in the process flow editor. So it is hard to model this logically.
    Would it be a good idea to write shell script that does similar things? You could check for a file, pauze and check again. Then error out or succeed...
    In the 10gR2 release of OWB you can completely model this using waits and loops.
    Thanks,
    Jean-Pierre

  • Check file existance in operating system

    Dear Collegues,
    Is there any function in oracle that checks a file existance located on local disk of windows computers?
    Like i have created a file c:\test.txt and i want to check through oracle function that this file exists or not.
    Regards,
    Imran Baig

    Is there any function in oracle that checks a file
    existance located on local disk of windows
    computers?Let's see if I understand the question correctly ...
    - You have two computers.
    - One is a client, the other is a database server.
    - You want to use an Oracle function, therefore you want to issue a request to the database server, asking the server if a file exists on the client.
    Is that correct?
    If it is correct, please tell us how the server mounts, or otherwise looks at, the client's disk? Once we have that answer, we might be able to answer your question ...

  • File Adapter - Check file exist before performing read

    Is there a feature in the file adapter or invoke activity for SOA 11.1.1.5 that performs a check to see if a specific file exists before it performs a read function? If file does not exist then move onto to next step, if it does then read it.
    I am trying to do this in 1 step instead of performing a listing of the directory first before perfomring the read.

    Hi,
    When you read a file, using the synchronous read file, you have to point to a file (file name, directory...). That way, when you are executing the invoke activity, followed by a FileAdapter, it's either the file exists, and you read it, or it's not exist and you don't read it.
    Arik

  • How to check file name in APP server

    Hi,
    Iam writing some files to APP server .Iam unable to check those files by using AL11. How to check those files in APP server?

    Hi,
    You can use this FM EPS_GET_DIRECTORY_LISTING.
    Also please try this FM /SAPDMC/LSM_F4_SERVER_FILE.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_apath.
    * Open the Browse Dialog Box on the Application Server
    CALL FUNCTION '/SAPDMC/LSM_F4_SERVER_FILE'
      IMPORTING
        serverfile = p_apath
      EXCEPTIONS
        canceled_by_user = 1
        OTHERS           = 2.
    IF sy-subrc <> 0.
    * No need to check for sy-subrc
    ENDIF.
    Regards,
    Ferry Lianto

  • How to download files by using applet?

    Hello folks,
    I am new to applet, and I want to write an applet to download multiple files from the applet-hosting server by using HTTP or socket. Any idea to achieve that? Using java.net.HttpURLConnection? or others?
    Appreciate your helpful replies.
    Joe

    In either Applet or AppletContext you should find 2 methods
    getCodeBase()
    getDocumentBase()
    it is possible that those methods may return the same URL although they might not depending on how everything's set up. But anyway you can use that to get a URL and use the URL to open a connection

  • How to check file name in local c drive and run exe file

    Hi All,
    I'm newbie user in action script. How can i check sepecific
    file name in local c:\ drive and if file doesn't exist in local
    drive download from server and run and if exist go to frame ..... .
    Please help to me.
    Thanks,

    Dear Marghoob Suleman
    Thank you very much for your kind help.
    Thanks in advance

  • How to check resource existance using standard web-services?

    Hi,
    There was the web-service KMNodeServiceStrdWSVi_Document in the SAP EP 7.0 that exposed the function "exists" checking whether the folder exists or not.
    SAP EP 7.3 does not contain KMNodeServiceStrdWSVi_Document web-service and I did not find any function in the  RepositoryFramework web-service.
    Is there any other web-service providing this functionality?
    Thanks in advance.

    Hi Arun,
    I got the data in the context in the response node .But the problem is that the web service returns an array of objects which inturns has array ob object, I m only able to get those values from the response node from the context which are simple string type.Could u pls tell me how can i get the complex data which is present in the response node in the context.
    Can i traverse the node(i.e) the rray in the context.CAn u tell me wat can i do.The response node has the complex structure as defined in the WSDL file ,i just need to get the data present in the array of that context which is populated by the web service.

  • How to attach files using an applet

    hi,
    i want to know how can i use an applet to upload or attach files in my application
    help me

    Hallo there,
    I am intrested on the same topic but I am not so good to modify the sound sdk demo. Is there anyone willing to share some code?
    Thanks
    Matteo

  • How to check files in the directory using JSP?.

    Hi,
    How can i check the file is directory or file and readable or writable and file size and type of file(Ex. jpg, txt, doc., etc). i want to list the specific type of file in the particular directroy.. please help me..
    Regards
    CHinna

    With the File class, using the methods isFile(), isDirectory(), canRead(), canWrite(), length() and getName()
    With File.listFiles() you can get a directory listing. If you want to limit the amount of files returned, you can pass your own FileFilter to it.
    http://java.sun.com/javase/6/docs/api/java/io/File.html

  • How to list files existing in a folder ??

    hello
    I want to lis all files that are existing in a folder
    MaApp\myFolder\
    note: myApplication is as executeable Jar file
    I do somthing like that
    File []fileList = (new File(this.getClass().getResource("/MyFolder/").getPath())).listFiles();
        for(int i=0; i < fileList.length; i++){
            String srcName = fileList.getName();
    System.out.println("Filename: "+srcName);
    // but java.lang.NullPointerException will be thrown
    what is to do ????
    thanks

    that is not what I ned
    so.
    Mypp contain mor folders
    myApp/Foder1
    myApp/Folder2
    myApp/Folder3/
    in Folder3 are more files file1.txt, file2.txt,file3.txt,...
    tol list the files wich exist in Folder3
      File []fileList = (new File("Folder3\\")).listFiles();
        for(int i=0; i < fileList.length; i++){
       }this works fine
    but wenn I create an executeable jar of myApp
    I becom an NullPointerException
    becaus there is problem with the path new File("Folder3\\")
    what I want how to let jar to know the path of hiles which are in Folder3
    thanks

  • How to Check files which is older than 14 days in particuler folder using IF condition in Batch script

    Hi,
    I have to check the zip files created before 14 days by using Batch script.
    Any conditional statement needed ?
    Thanks,
    Jitu

    But this script is failing if the files are not present in the same folder.
    So I am thinking to loop the statement to check if files are not there exit from the loop.
    The script does not fail - it reports that no files are found. You can detect this like so:
    if %ErrorLevel% NEQ 0 echo "There are no zip files!"
    There is no loop in your script that you can exit from.

  • How to check file format in application server?

    Hi guys,
    i have an inbound zip file(which contains PDF files) in the application server .I need to check if the file is in base 64 format or in hexadecimal format.Can any one help me out with the suggestions or with probable solution.
    Regards
    Snehasish

    Thanks for your reply.i am able to get the the zip file data in xstring with following code .
    .now what should be logic to determine that the data in xstring is in base 64 or in hexadecimal format?
    data: lv_zip type xstring.
    OPEN DATASET lc_file FOR INPUT IN binary MODE.
    IF sy-subrc = 0.
    read dataset lc_file into lv_zip.
    endif.
    CLOSE DATASET lc_file.
    Regards
    Snehasish

Maybe you are looking for

  • Can no longer play music that I previously purchased

    After performing the iTunes and Quicktime upgrades last night, I discovered today that I can no longer play songs that I previously downloaded from the music store. I also cannot preview any songs in the music store, and I'm assuming that if I actual

  • My iPhone 4 doesn't connect to any wifi sources anymore (even though it used to) and regularly cuts out of service.

    My iPhone is from the US and I've had it for nearly two years. I'm with optus. I know that this is not allowed to be discussed but my phone was bought jailbroken. Neither my father nor I had any idea what this meant at the time and would not have bou

  • Using plain j2se adapter

    Hi Experts, This is regarding j2se adapter engine. I dont have any idea to use j2se adapter engine. I checked this URL: http://<IPAddress>:8200 , changing the ip but it is not working. How can I check whether it is installed in my system ? Thanks Rab

  • JFRAME- JPANEL question

    I have a JFrame that holds a JPanel. If that JPanel needs to contact the JFrame how do I get access to parent? I tried panelname.getParent, when I did I got a java.lang.ClassCastException Any help would be great. Brock

  • Question about String initialization~~~

    String a = "sss"; String b = "sss"; the result of a==b is true . String a = new String("sss"); String b = new String("sss"); however , the result of a==b is false . why? the operator "==" compares WHAT of two object ?? thanks , ;[