How to check whether a file exist in the program folder or not?

Hi guys,
how to check whether a file exist in the program folder or not? Let is say i recieve a file name from user then i want to know if the file is there not and act on that base.
abdul

Look at the class java.io.File and the .exists() method:
http://java.sun.com/j2se/1.4/docs/api/java/io/File.html

Similar Messages

  • How to check whether a file exists or not

    i am in an image uploading utility. i hav succesfully uploaded the image to the server directory (say /uploads). but when displaying the uploaded image, i wanna show the picture only if the image exits (bcoz for some records there is no image). so i hav used this code
    if(new File("uploads/1.jpg").exists())
         out.print("image exists");
    but its not working for me. i got it working fine when i give the full path "D:/Tomcat/webapps/diary/admin/uploads/1.jpg". but i think giving this absolute path is not an efficient method bcoz its a web application, bcoz i may not be able get the absolute path always. so how can i do this by specifieing the relative path
    help me ASAP if u can
    aleens

    Haii ameen
    This is one way to rectify your problem..
    if(new File("uploads/1.jpg").exists())
    out.print("image exists");
    instead of this u can write like
    <%
    ServletConfig cf=getServletConfig();
    ServletContext c=cf.getServletContext();
    if(new File(c.getRealPath("uploads")+"/test.txt").exists())
    out.print("image exists");
    %>If u are not clear of what it is done let me know..i will xplain to you furthur...
    Happy New Year
    Shanu

  • JavaScript: How to check if a file exists.

    Hello Everybody,
    Can you tell me how to check if a file exists using JavaScript and Internet Explorer.
    Browsing on this website I could read about the command "f.exists()" and it was necessary to include "java.io.*".
    Should I use this same command and should I include the same files? Or are there other files and other commands?
    Thanks in advance.

    sorry ya. there is no command to check whether a file exists using javascript. The following code says the object name and value. But it can't say whether the file exists in the harddisk or .. Javascript cannot access database and system resources. If the file exists or not can be checked through the application (ASP, CFML, ..) you are using.

  • How to check whether a file is present in the UNIX directory of app. server

    Hi,
            I am creating files in the UNIX directory in the application server using :
                       CONCATENATE '/sapmnt/RD1/interfaces/client670/'
                       p_fname '.CSV' INTO w_filename.
               OPEN DATASET w_filename FOR OUTPUT IN TEXT MODE.
              LOOP AT t_output1.
                      TRANSFER t_output1 TO w_filename.
              ENDLOOP.
             CLOSE DATASET w_filename.
    I am unable to check whether a file with the same name exists or not. How to check the duplicate state of the file.

    You can use the following fm
    RZL_READ_FILE
    or
    use OPEN DATASET FOR INPUT.

  • How to check whether a file got read permissions for perticular user

    Problem: Let JRE is running with some x as effective user in LINUX then while checking file permission it is checking permission on that file for that x user.
    File f = new File(�file name�)
    if(f.exists())
         System.out.println(�exists�);
    Else
         System.out.println(�does not exists�);
    The above code prints exists only when x user have permissions on that file
    Requirement: I would like to check whether a file got read permissions for particular user i.e. whether y user got permissions on that file.
    Any help is appreciated

    In Linux a user has to have read permission on a file to even see that it exists. As a result, if a user (or a group to which they belong) doesn't have read access to the file File.exists() will return false. Windows which doesn't have as tightly controlled access to files will admit that a file exists whether it can be read or not.
    PS.
    This is proof that I should never answer a question off the top of my head when I haven't had my red bull yet. This is wrong. You will be able to see it if you have read and execute on the directory.
    thumps self in head
    Message was edited by:
    puckstopper31

  • How to check whether portal user exists or not using UM API.

    Hi Experts,
    Let us say i need to create an user account "PortalUser",i know how to create an user,setting first name,lastname,password for that.
    but here before creating the portal user, i need to check whether that user exists or not.If user already exists ,then i  need to skip the below for creating the user.
    IUserFactory userFact = UMFactory.getUserFactory();
    IGroupFactory groupFact = UMFactory.getGroupFactory();
    IRoleFactory roleFact = UMFactory.getRoleFactory();
    IUser tuser = userFact.getUserByLogonID("PortalUser");
    IUserMaint newUser = userFact.newUser("PortalUser");
    newUser.setFirstName("PortalUser");
    newUser.setLastName("Test");
    newUser.setEmail("PortalUser.Testatgmaildotcom");
    //Locale PortalLanguage = new Locale(Lang.toLowerCase(), "");
    Locale PortalLang=new Locale("en");
    newUser.setLocale(PortalLang);
    newUser.save();
    newUser.commit();
    IUserAccount userAcc = UMFactory.getUserAccountFactory().newUserAccount("PortalUser", newUser.getUniqueID());
    userAcc.setPassword("test1test$");
    userAcc.save();
    userAcc.commit();     
    Thanks in advance.
    Thanks
    Sony.

    Hi,
    Try this code,
    IUserFactory factory = UMFactory.getUserFactory();
    IUser user = factory.getUserByLogonID(userId);
    lastName = user.getLastName();
    firstName = user.getFirstName();
    refer this pdf,its very helpful
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/events/webinars-nw-rig/using%20the%20user%20management%20api%20with%20ep%20applications%20-%20webinar%20powerpoint.pdf
    Regards,
    Sunaina Reddy T

  • How to check whether transport path exist between two systems in sld??

    Hi,
         I have two systems namely 'A' and 'B' and created business systems for both of them.Then i created transport path between the two systems.How i check whether what i have done is right in SLD.

    <b>WRT to CMS</b>
    am not sure with this but u can try:
    1. Start CMS: http://<host>:<J2EE Engine http port>/webdynpro/dispatcher/sap.com/tcSLCMS~WebUI/Cms.
    2. Goto lansdscape configurator and check there
    Message was edited by:
            Prabhu  S

  • How to check whether a file in AL11 is unicode or non-unicode

    Hi All,
    I have a file in AL11. Now before using open dataset, i need to check whether it is unicode or not. By doing this we will know what encoding format needs to be used with open dataset statement.
    Do we have any way by which we can programatically check whether a file in AL11 is unicode or not.
    Thanks,
    Tirth

    Hi,
    The code is as follows:
    IIndexService indexService = null;
    try {
       indexService = (IIndexService) ResourceFactory.getInstance().getServiceFactory().getService(IServiceTypesConst.INDEX_SERVICE);
    } catch (ResourceException e) {
       if (indexService == null) {
         log.errorT("Error on instanciating the index service");
         return this.renderMessage(this.getBundleString(RES_NO_INDEX_SERVICE), StatusType.ERROR);
    // get index
    IIndex index = null;
    try {
       index = indexService.getIndex("YourIndexID");
    } catch (WcmException e1) {
       log.errorT("Error when trying to get the index");
       return this.renderMessage(this.getBundleString(RES_NO_INDEX), StatusType.ERROR);
    // check if the index is a instance of AbstractClassificationIndex
    AbstractClassificationIndex classiIndex = null;
    if (index instanceof AbstractClassificationIndex) {
       classiIndex = (AbstractClassificationIndex) index;
    } else {
       log.errorT("The index " + index.getIndexName() + " is no classification index");
       return this.renderMessage(this.getBundleString(RES_NO_CLASSIFICATION_INDEX), StatusType.WARNING);
    //give your KM Resource here for which you want to know if it is classified or not
    boolean classified = classiIndex.isDocClassifiedInAnyTax(resource);
    Regards,
    Praveen Gudapati

  • How can I get settings files out of the Library folder?

    I had to do a clean reinstall (erase & reinstall) to clear up some problems on my Mac. Unfortunately, when you do this, your settings, customizations, bookmarks etc. aren't transferred over as they do when you upgrade in the normal way.
    For example, dashboard widgets are in each user's <home folder>/Library/Widgets folder.
    I could restore some of these settings by dragging the settings files from the old System Folder to the new one. Unfortunately, Apple is making this harder by hiding the Library folder in the user folder, both on the Mac and on the backup drive.
    There is a command to enter in Terminal to show your Library folder, but this only seemed to work on the Mac and not on my backup drive.
    How can I get key settings files out of the Library folder on my backup drive when the Library folder is hidden?
    Thanks

    Open the enclosing folder, choose Go to Folder from the Finder's Go menu, and provide Library as the path.
    (80699)

  • How to check whether a Record Exists or not in Ztable

    Hi all,
    I have Req like this
    In ZTable i have 2 fields  * Legacy System , Legacy Material No*
    Environment Value is coming in one of the field in Idoc
    The logic is if the Environment Value is UK and a Record Exists on the ZTable for Legacy Sysyetm = Leg1 means i have send Legacy Material No , else  Send 01
    Please suggest me the process for this
    REgards
    Vamsi
    Edited by: Vamsi Krishna on May 19, 2009 5:31 PM

    Hi Michal / Aamir,
    Thanks for your replies.
    The ZTable is at R/3 side only, iam using RFC Lookup for this, but iam bit confuse on how to construct the logic to check whether there is a record Exists or not on Ztable
    Logic shld be If the Environment value is UK and a record exists on the Ztable for Legacy system "ABC" means then send Legacy material number else send 01
    In Table we will have the fields Legacy System   Legacy Material No  & Environment value is coming from Idoc itself( Ex: UK or US)
    Regards

  • How to check whether a node exist in a Particular Level. (xmltype)

    hi,
    please help me to check whether a particular node exists in one level.
    for eg
    I have the following xml
    <map>
         <entry>
              <key>
                   heading1
                   </key>
              <map>
                   <entry>
                        <key> sub1 heading1</key>
                        <value> sub1 heading1 value  </value>
                   </entry>
                   <entry>
                        <key> sub2 heading1 </key>
                        <value> sub2 heading1 value  </value>
                   </entry>
              </map>
         </entry>
         <entry>
              <key>
                   heading2
                   </key>
              <map>
                   <entry>
                        <key> sub1 heading2</key>
                        <value> sub1 heading2 value  </value>
                   </entry>
                   <entry>
                        <key> sub2 heading2 </key>
                        <value> sub2 heading2 value  </value>
                   </entry>
              </map>
         </entry>
    </map>i need to check how many heading exists in this xml.
    I am checking like
            i:=1;
         l_section := ip_xml.extract('//map/entry');
         WHILE l_section.existsnode('entry[' || i|| ']') = 1 LOOP
              // extract the key name within entry tag
                  // print the key name.
    i:=i+1;
         end loop;but iam getting all the key name like
    heading1
    sub1 heading1
    sub2 heading1
    heading2
    sub1 heading2
    sub2 heading2
    I need only heading1 and heading2. how can I check whether a particular node exist in particular level.
    first level , second level etc. Please help

    but iam getting all the key nameThat's because you're using a descendant axis : //map/entry
    SQL> DECLARE
      2 
      3   ip_xml  xmltype := xmltype('<map>
      4       <entry>
      5            <key>
      6                 heading1
      7                 </key>
      8            <map>
      9                 <entry>
    10                      <key> sub1 heading1</key>
    11                      <value> sub1 heading1 value  </value>
    12                 </entry>
    13                 <entry>
    14                      <key> sub2 heading1 </key>
    15                      <value> sub2 heading1 value  </value>
    16                 </entry>
    17            </map>
    18       </entry>
    19       <entry>
    20            <key>
    21                 heading2
    22                 </key>
    23            <map>
    24                 <entry>
    25                      <key> sub1 heading2</key>
    26                      <value> sub1 heading2 value  </value>
    27                 </entry>
    28                 <entry>
    29                      <key> sub2 heading2 </key>
    30                      <value> sub2 heading2 value  </value>
    31                 </entry>
    32            </map>
    33       </entry>
    34  </map>');
    35 
    36  BEGIN
    37 
    38    for r in (
    39      select heading, headno
    40      from xmltable( '/map/entry/key'
    41                     passing ip_xml
    42                     columns heading varchar2(30) path '.'
    43                           , headno  for ordinality )
    44    )
    45    loop
    46      dbms_output.put_line('Heading '||r.headno||' = '||r.heading);
    47    end loop
    48    ;
    49 
    50  END;
    51  /
    Heading 1 =
                   heading1
    Heading 2 =
                   heading2
    PL/SQL procedure successfully completed

  • How to check if a user exists in the system ?

    Dear Gurus,
    I want to check whether a user ID exists in the system after logon by using VBA. If the user ID exists, then I will update the user's information with external data by using the method user.change.
    When running below codes, error occurs and error msg is: "The persistent key for an business object instance of type USER has not been set. Cannot invoke method EXISTENCECHECK"
    How can I do to check the user ID existence ?
    Set oUser = oBAPICtrl.GetSapObject("user")
    oUser.ExistenceCheck "MyUserID", return:=oReturn
    Thanks and Regards,
    Bao Yan

    Mickey,
    I'm afraid I never did get this to work properly. However, in the way of all bad/good (delete as appropriate) programmers eveywhere I worked around this problem. I was using this code in Banner.asp to change the view based on the user group so if a given session variable was set a user would see a different view. It works fine with no slow down on the page and you should be able to adapt it to what you need.
    Hope this helps.
    Neville
    Note: Application variables are ones I have defined in config.xml.
    Code follows:
    <!--START:INC\common\getgroup.asp-->
    <% 'NAH 29/03/2004 ' 'This check the to see if the current user has the group in their membership that has been defined as the group to provide an alternative view of the portal.' 'The group variable is defined in the config.xml as "ALTVIEWGROUP"'
    'Do not do this is we have already matched the group'If Session("groupMatch") <> "1" and Session("groupMatch") <> "2" then
    Dim pGroup
    pGroup = Application("ALTVIEWGROUP") Set Session("groupMatch") = nothing
    Dim Plumtree
    Set Plumtree = Server.CreateObject("ADODB.Recordset") Plumtree.ActiveConnection = "Driver={SQL Server};Server=" & Application("DBSERVER") & ";Database=" & Application("PLUMTREEDB") & ";" Plumtree.Source = "SELECT GROUPID FROM " & Application("PLUMTREEDBUSER") & ".PTGROUPMEMBERSHIP WHERE (USERID = " & strUserID & ") AND (GROUPID = " & pGroup & ")" Plumtree.CursorType = 3 Plumtree.CursorLocation = 2 Plumtree.LockType = 1 Plumtree.Open()
    'If there are records we should have a match otherwise set the session varible to no match.' If Plumtree.EOF then Session("groupMatch") = "2" Else 'By getting here the user should have the matching group but complete one final check to make sure' If cInt(Plumtree.Fields.Item("GROUPID").Value) = cInt(pGroup) then Session("groupMatch") = "1" Else Session("groupMatch") = "2" End If
    End If
    Plumtree.Close() Set Plumtree = Nothing
    End if%><!--END:INC\common\getgroup.asp-->

  • How to check if a constraint existed in the table and drop it?

    Hi all,
    I want to drop a constraint from a table. I do not know if this constraint already existed in the table. So I want to check if this exists first.
    Below is my query:
    DECLARE
    itemExists NUMBER;
    BEGIN
         itemExists := 0;
    SELECT COUNT(CONSTRAINT_NAME) INTO itemExists
    FROM ALL_CONSTRAINTS
    WHERE UPPER(CONSTRAINT_NAME) = UPPER('my_constraint');
    IF itemExists > 0 THEN
    ALTER TABLE my_table DROP CONSTRAINT my_constraint;
    END IF;
    END;
    Here is the error I got when I executed the above query:
    ORA-06550: line 11, column 5: PLS-00103: Encountered the symbol "ALTER" when expecting one of the following: ( begin case declare exit for goto if loop mod null pragma raise return select update while with <an identifier> <a double-quoted delimited-identifier> <a bind variable> << continue close current delete fetch lock insert open rollback savepoint set sql execute commit forall merge pipe purge
    Please help me with this!
    Greatly appreciate!
    Khoi Le

    Yes, I also tried to put the pl-sql in the Execute Immediate. However, the error still remains
    EXECUTE IMMEDIATE 'DECLARE
    itemExists NUMBER;
    BEGIN
         itemExists := 0;
    SELECT COUNT(CONSTRAINT_NAME) INTO itemExists
    FROM ALL_CONSTRAINTS
    WHERE UPPER(CONSTRAINT_NAME) = UPPER('my_constraint');
    IF itemExists > 0 THEN
    ALTER TABLE my_table DROP CONSTRAINT my_constraint;
    END IF;
    END';
    I execute the above code via running the batch file.
    Here is the error after I ran the batch file:
    ORA-06550: line 11, column 5:
    PLS-00103: Encountered the symbol "ALTER" when expecting one of the following:
    ( begin case declare exit for goto if loop mod null pragma
    raise return select update while with <an identifier>
    <a double-quoted delimited-identifier> <a bind variable> <<
    continue close current delete fetch lock insert open rollback
    savepoint set sql execute commit forall merge pipe purge
    The symbol "lock was inserted before "ALTER" to continue.
    ORA-06550: line 11, column 53:
    PLS-00103: Encountered the symbol "DROP" when expecting one of the following:
    . , @ in <an identifier>
    <a double-quoted delimited-identifier> partition subpartition
    ORA-06512: at line 2117
    I can not manually drop it. I need to do this via running an update script file.
    Is there a different way to accomplish this?
    Thank you very much!

  • How to check whether a table exists in database

    test9997 is table already made in database with 3 columns :1st-varchar,2nd-number,3rd-number
    declare
    var1 varchar2(20);
    var2 number(20);
    var3 number(20);
    begin
    plvar1 :='this is again pl/sql';
    plvar2 := 12;
    plvar3 := 13;
    IF (???? condition for existence of table say test1111??????) then
    create table test1111(
    var1 varchar2(20);
    var2 number(20);
    var3 number(20);
    insert into test1111(plvar1,plvar2,plvar3);
    else
    insert into test1111(plvar1,plvar2,plvar3);;
    end if;
    end;
    in the above code i want to check existence of a table and insertion or updation will be based on it after creation if it doesnt exist.
    how to do it
    please help asap

    You're in the wrong forum (this one is for issues with the SQL Developer tool). You'll get more answers in the SQL And PL/SQL forum.
    Have fun,
    K.

  • How to check whether INSO Filer is being used or not?

    Hi,
    We have created full text search indexes using the default syntax -
    CREATE INDEX FTI ON DOCUMENTS(DOC_FILE) INDEXTYPE IS CTXSYS.CONTEXT;
    How can I find out whether the INSO filter is used or not. Also a basic question, INSO filter helps in reading and "crawling" some 100+ document formats and creating an index against which search could be executed.... right?
    Please do let me know.
    Thanks & Regards,
    Dhwanil

    you can specify the inso filter in index code creation.
    create index TEST_IDX
    on TEST_TABLE (TEXT)
    indextype is ctxsys.context
    parameters('filter     ctxsys.inso_filter');

Maybe you are looking for

  • Pass function name as parameter in SSRS expression

    I have a function (GetColumnFieldName) which returns string datatype Now I want to use this function in below SSRS expression =Code.GetDisplay("FirstName",Parameters!SelectedCols.Value,Parameters!DisplayCols.Value) At the above expression I want to r

  • How can I add a Drawing Markup/Annotation to my stamp while it's being stamped?

    I have created Dynamic Stamp and works perfect and its located in my user profile: C:\Users\XXXXX\AppData\Roaming\Adobe\Acrobat\10.0\Stamps\symbols.php And this works just fine... Now I want to add a line to the stamp. I want the user to introduce th

  • Import and package does not exist

    I have a program and I wish to import a package that I've made. I have tried to do this with: import clientcode.*;but I keep getting the error message java:8: package clientcode does not exist I am completely new to Java and have no idea how to get a

  • How to handle empty columns

    Hi guys, I have a template like below for each Field1 Field2 Field3 Field4 Field5 Field5 end for each I used a if condition to hide the field when the value is null. The report looks like below Field1 Field2 Field3 NULL NULL Field6 Field7 NULL NULL Q

  • Unknown album in my photos

    There is an album in my photos that just appeared on it's own and I can't delete it. The album is called Yttg. Bhbbbnbjbh bbjkjjjj....  any ideas or thoughts as to where this came from and how to get rid of it?