How to determine if a file is existing

Hi,
do we have a way to detect if a is existing in java? apparently I use RandomFileAccess to load my file however, I'd like to check in advance if the file is existing already.

I use RandomFileAccess to load my file however, I'd like to check in advance if the file is existing already.Bad idea. Pointless waste of time and space. What if the file exists when you pre-check but isn't there when you open it?
Just catch the FileNotFoundException that the RandomAccessFile will throw. Much simpler. You have to catch IOExceptions anyway ...

Similar Messages

  • How to update an image file into existing file

    how to update an image file into existing file

    Hi,
    So, i assume you want to change one picture. On Stage, i have edgeAnimate (an image), and
    1) i am using the div tag.
    So: sym.$("edgeAnimate").css("background-image", "url(images/myImage.png)" ); will change my picture.
    Link: CSS properties.
    More CSS:
    sym.$("edgeAnimate").css( { "background-image": "url(images/myImage.png)", "background-size": "100% 100%", "background-repeat": "no-repeat", "cursor": "pointer" } );
    Using a path variable:
    var myPath = "images/myImage.png";
    sym.$("edgeAnimate").css( { "background-image": "url("+myPath+")", "background-size":"100% 100%", "background-repeat":"no-repeat", "cursor": "pointer" } );
    2) i am using the img tag.
    I can add a class using Edge Animate user interface.
    I choose one class name: "newImage".
    So:  sym.$(".newImage").css("background-image", "url(images/myImage.png)" ); will change my picture.
    Note: I assumed you don’t need to preload your picture.

  • How to determine whether a file doesn't exist or doesn't have enough perms

    Hello everone,
    I am stuck in determining whether a file does not exist or does not have enough permissions so that access to this file is denied?". I am using
    java.io.File.exists() or java.io.File.canRead() methods to check this but both of them just return false in both above mentioned cases.
              In the documentation however its mentioned that these method throw SecurityException - If a security manager exists and its SecurityManager.checkRead(java.lang.String) method denies read access to the file. But then problem is to write a security manager which denies
    read access if the file does not have permissions so that exception can the thrown.
    Any suggestions or pointers will be highly appreciated.
    Thank You.
    Regards,
    Vikash Kumar

    Some platforms will let you rename or remove an open
    file.Unless those platforms support file locking, and the file has a lock on it.

  • How to check if a file (picture) exists into a war?

    Hello, I have made a Java/J2EE project using countries in the world and I have at my disposition a folder of flags icons.
    Some countries don't have any flag icon for any reason and in my application, I'll be able to add new ones.
    In my code, I want to do display the flag of the current country if available else display a default icon.
    Here is what I am currently doing:
    String contextPath = facesContext.getExternalContext().getRequestContextPath();
    String flagUrl = contextPath + "/images/flags/"+ name.trim().toLowerCase() + ".png";
    boolean exists = (new File(flagUrl)).exists();The issue is exists is always set to true no matter the existence of the flag.
    Here is what my variable nammed flagUrl looks like : /images/flags/ca.png
    How do you check the existence of a file into a war? Thank you
    Edited by: cotede3 on Mar 11, 2010 5:32 AM

    Unfortunately I cannot call getRealPath on application.
    application in my code is :
    BBrApplication application = null;
              // Searchs entity class icon
              FacesContext facesContext = FacesContext.getCurrentInstance();
              if (facesContext != null)
                   application = BBrApplication.getInstance(facesContext);So I tried
    String realFilePath = application.getContextRoot();but I end up with
    realFilePath = /DFP/.
    so It is not the absolute path displayed...
    How can I do ?

  • How to determine in an XML node exists in Coldfusion

    If I have XML that looks something like this:
    <manifest>
        <state ID="20" name="State 2">
            <person>john.black</person>
        </state>
        <state ID="30" name="State 2">
            <person>bill.doe</person>
            <group>Group2</group>
        </state>
    </manifest>
    Where <group> may or may not exist under <state>, how do I determine if <group> exists when I'm parsing this XML? 
    This is the code I'm working with currently:
    <cfset szXMLFile = "Manifest.xml">
    <cfset XMLDoc = xmlParse(szXMLFile)>
    <cfset StateNodes = xmlSearch(XMLDoc,'/manifest/state')>
    <cfoutput>
    <cfloop from="1" to="#ArrayLen(StateNodes)#" index="i">
        <cfset StateXML = xmlparse(StateNodes[i])>
        <cfloop index="p" from="1" to="#ArrayLen(StateXML.state.person)#">
            <cfoutput>Person: #StateXML.state.person[p].xmltext#</cfoutput><br />
        </cfloop>
        <cfloop index="g" from="1" to="#ArrayLen(StateXML.state.group)#">
            <cfoutput>Person: #StateXML.state.group[g].xmltext#</cfoutput><br />
        </cfloop>
    </cfloop>
    </cfoutput>
    I suppose I could just put <try><catch> blocks around where I'm referencing <group> and if it doesn't exist, I'll just handle it that way - but that seems like such a hack.  Is there a 'real' way to determine if the node actually exists? 
    Thanks! 

    <cfif structKeyExists(StateXML.state, "group")>
        <cfloop index="g" from="1" to="#ArrayLen(StateXML.state.group)#">
            <cfoutput>Person: #StateXML.state.group[g].xmltext#</cfoutput><br />
        </cfloop>
    </cfif>

  • How to check if the file already exists in the client directory

    Hi all.
    I'm on devsuite 10g. I'm using webutil to download files from DB using webutil function db_to_client.
    What I need is to check if the file already exists in the client directory and if yes to display a message to ask the user if he wants to overwrite or no. How can I make this???
    Here is the code that I'm using to download the file.
    Thanks all for the collaboration.
    Fabrizio
    declare
    file_path varchar2(2000) := null;
    BEGIN
    /** I ask where saving the file on the client machine **/
    file_path:= webutil_file.file_selection_dialog
    (directory_name => null,
    file_name => :bin_docs.name,
    file_filter => '',
    title => 'Saving file',
    dialog_type => save_file, --save_file
    select_file => TRUE);
    /** I download the file from DB to client **/
    if webutil_file_transfer.DB_To_Client_With_Progress
    ( file_path ,
    'BIN_DOCS',
    'DOC' ,
    'doc_id = '||:bin_docs.doc_id,
    'Downloading file',
    ' '||:bin_docs.name) then
    msg_alert('Download del file avvenuto con successo','I',false);
    else
    msg_alert('Si è verificato il seguente errore in fase di download '||SQLERRM,'I',false);
    end if;
    end;

    How about something like the below:
    Note: I have a yes/no alert to asking if they want to over-write the existing file.
    DECLARE
    file_path VARCHAR2(2000) := null;
    over_write BOOLEAN := TRUE;
    BEGIN
    /** I ask where saving the file on the client machine **/
    file_path:= webutil_file.file_selection_dialog
    (directory_name => null,
    file_name => :bin_docs.name,
    file_filter => '',
    title => 'Saving file',
    dialog_type => save_file, --save_file
    select_file => TRUE);
    IF webutil.file_exists(file_path) THEN
    /** check a file by the same name exists in the selected directory **/
    IF show_alert('Ask_overright') != alert_button1 THEN
    /** If we say no then set over_write value to false **/
    over_write := FALSE;
    END IF;
    END IF;
    IF over_write THEN
    /** I download the file from DB to client **/
    IF webutil_file_transfer.DB_To_Client_With_Progress
    ( file_path ,
    'BIN_DOCS',
    'DOC' ,
    'doc_id = '||:bin_docs.doc_id,
    'Downloading file',
    ' '||:bin_docs.name) then
    msg_alert('Download del file avvenuto con successo','I',false);
    ELSE
    msg_alert('Si è verificato il seguente errore in fase di'
    ||' download '||SQLERRM,'I',false);
    END IF
    END IF;
    END;
    cheers
    Q

  • How to determine the type of an existing iView

    Hi,
    While creating an iView using wizard there is a big list of type of iViews. But after creation of iView, how do I determine the type of iView. Which attribute or property of iView holds this information?
    -Lave Kulshreshtha

    You can copy and paste the existing Iview changing the name and ID if u want to replicate the same.
    Also, when you create a new iView from a template, you get a list of them e.g SAP BSP iView etc.
    Now what you see in the code link is much similar to what you see as a list of templates when u create iViews. So its pretty simple.
    I hope this helped you.

  • How to check if the file already exists in the application server directory

    Hi all. I'm on devsuite 10g.
    I transfer file from local machine to application server using webutil function webutil_file_transfer.client_to_as and I want to check if the file I'm transfering already exists on the server directory.
    How can I make this?
    Thanks all,
    Fabrizio

    use the text_io package and open the file in read-mode.
    like this
    declare
    xFileType text_io.file_type;
    begin
    xFileType := text_io.fopen('c:\temp\test.txt','R'); --file on the middle tier
    -- file exists;
    text_io.fclose(xFileType);
    exception
    when others then
    --file doesn't exist
    end;
    regards
    Christian

  • How can I view pdf files that existed before I downloaded a newer reader version?

    I'm unable to view older pdf files after downloading the newest version of reader! How can I fix this?

    They should open the same as they did with the older version.
    How are you trying to open (double clicking, using file>Open from within Reader, clicking on a link on a webpage...etc) them and what happens when you try?

  • How to create a new file with existing file's resource fork?

    Hello,
    I would like to create a new file that has the resource fork of an existing file. I had though of making a copy of the existing file, seek to the beginning of the copy and write the new data, but for large files, that creates the whole file even when not needed. I currently create the new file with [NSFileManager createFileAtPath: contents: attributes:], but attributes do not include resource fork items, like custom icons, color label, etc.
    [NSURL resourceValuesForKeys] gives a common subset of resource data, like icons and color label, but that's about it. Is there some way to get the resource fork or a copy of the file without getting the whole file?
    Thanks

    What are you trying to do here? While resource forks might still be quasi-supported, you really shouldn't be thinking about them as such. Instead, think in terms of extended attributes. You can use the low-level xattr() functions to get some of that or you can use the new NSURL methods.

  • How to check if a file already exists or not

    javax.swing.filechooser.FileFilter filter = new FileNameExtensionFilter("CSV Files","csv");
                   final JFileChooser fileSelect = new JFileChooser();
                   fileSelect.addChoosableFileFilter(filter);
                   int action = fileSelect.showSaveDialog(JFrame)
                   try{
                        if (action == JFileChooser.CANCEL_OPTION)
                             return;
                        else if (action == JFileChooser.APPROVE_OPTION)
                             SwingUtilities.invokeLater(new Runnable()
                                  public void run()
                                       file = fileSelect.getSelectedFile();
                                       JOptionPane.showMessageDialog(null,file);
                                       if (!file.exists())
                                            JOptionPane.showMessageDialog(null,file.isDirectory());
                                       //fetches the file name from the file name filed in the GUI
                                       final String fileName = ((BasicFileChooserUI)fileSelect.getUI()).getFileName();
                                       if(!fileName.endsWith(".csv"))
                                            //appends the file type to the fetched filename
                                            ((BasicFileChooserUI)fileSelect.getUI()).setFileName(fileName + ".csv");
                                       final String newFileName = ((BasicFileChooserUI)fileSelect.getUI()).getFileName();
                                       //replace the oldfile with filename.csv
                                       String csvFile = file.getPath().replace(file.getPath().substring(file.getPath().lastIndexOf('\\') + 1,file.getPath().length()),"");
                                       file = new File(csvFile.concat(newFileName));
                                       if(file.exists())
                                            JOptionPane.showMessageDialog(null,file);
                                            int response = JOptionPane.showConfirmDialog (null,
                                                      "Overwrite existing file?","Confirm Overwrite",
                                                      JOptionPane.OK_CANCEL_OPTION,
                                                      JOptionPane.QUESTION_MESSAGE);
                                            if (response == JOptionPane.CANCEL_OPTION)
                                                 return;
                                            else
                                                 try
                                                      writeToFile();
                                                 catch (IOException e)
                                                      e.printStackTrace();
                                       else
                                            try
                                                 writeToFile();
                                            catch (IOException e)
                                                 e.printStackTrace();
                   catch(Exception e)
                        e.printStackTrace();
                   }

    Thank u very much
    I got the solution for it
    if(ae.getActionCommand().equals("Export"))
                   data= new Vector();
                   data.addAll(tabData);
                   javax.swing.filechooser.FileFilter filter = new FileNameExtensionFilter("CSV Files(*.csv)","csv");
                   final JFileChooser fileSelect = new JFileChooser();
                   fileSelect.addChoosableFileFilter(filter);
                   int action = fileSelect.showSaveDialog(MainFrame.getMainFrame());
                   try{
                        if (action == JFileChooser.CANCEL_OPTION)
                             return;
                        else if (action == JFileChooser.APPROVE_OPTION)
                             SwingUtilities.invokeLater(new Runnable()
                                  public void run()
                                       file = fileSelect.getSelectedFile();
                                       //fetches the file name from the file name filed in the GUI
                                       final String fileName = ((BasicFileChooserUI)fileSelect.getUI()).getFileName();
                                       if(!fileName.endsWith(".csv"))
                                            //appends the file type to the fetched filename
                                            ((BasicFileChooserUI)fileSelect.getUI()).setFileName(fileName + ".csv");
                                       final String newFileName = ((BasicFileChooserUI)fileSelect.getUI()).getFileName();
                                       //replace the oldfile with filename.csv
                                       String csvFile = file.getPath().replace(file.getPath().substring(file.getPath().lastIndexOf('\\') + 1,file.getPath().length()),"");
                                       JOptionPane.showMessageDialog(null,csvFile);
                                       if (csvFile.endsWith("\\" + "\\"))
                                            csvFile = csvFile.concat(fileName.concat("\\"));
                                       file = new File(csvFile.concat(newFileName));
                                       if(file.exists())
                                            int response = JOptionPane.showConfirmDialog (null,
                                                      "Overwrite existing file?","Confirm Overwrite",
                                                      JOptionPane.OK_CANCEL_OPTION,
                                                      JOptionPane.QUESTION_MESSAGE);
                                            if (response == JOptionPane.CANCEL_OPTION)
                                                 return;
                                            else
                                                 try
                                                      writeToFile();
                                                 catch (IOException e)
                                                      e.printStackTrace();
                                       else
                                            try
                                                 writeToFile();
                                            catch (IOException e)
                                                 e.printStackTrace();
                   catch(Exception e)
                        e.printStackTrace();
    Message was edited by:
    vijaysforum

  • How to "import" SampleApp repository file to existing repository

    Hello
    I use OBIEE 11.1.3.5
    I woudl like to prepare some kind of training for my business users so I need sample app enviroment in my production enviroment.
    I know how to "move" presentation content but I'm not able to merge this two repositories (repository from SampleApp and my production repository). I tried in different ways toll merge repositoru never with full success . (My production repository was upgraded from 10g - maybe this is reason). I tried also copy paste but I have problem with chaged join names (on the fly )in new repository.
    Is someone who know how "import"/"merge" both repositeries and could be helpfull :)

    Hi,
    Refer,
    http://www.oracle.com/webfolder/technetwork/tutorials/obe/fmw/bi/bi11115/import_merge/merging_importing_11g.htm
    http://www.rittmanmead.com/2010/07/obiee-11gr1-incremental-patches-to-the-rpd/
    Thanks
    Deva

  • How to autoextend just one file from existing tablespace?

    Hi,
    I discover some of the tablespaces did not have autoexent feature, i.e. none of the datafiles have been autoextend features
    so I need to autoextend it, hopefully the data file which has the most free space. So it would be good if I can come up with a query to find out which datafile belonging to a tablespace which currently has the highest free space could be selected for extend features,
    To get me on the right track,
    which dynamic views/data dictionary do I need to look up?
    v$datafile/v_$datafile
    dba_free_space
    v$tablespace
    when should I use v$datafile? when should I use v_$datafile.
    thanks a lot!

    There seems to be some basic confusion.
    AUTOEXTEND is not going to reuse the space within a data file; it is going acquire more space for the same file on the disk.
    You can lookup dba_data_files.autoextensible column to check if your file is autoextensible or not.
    when should I use v$datafile? when should I use v_$datafile.v$datafile is just a synonym for v_$datafile.

  • How to Determine Text File Encoding is UNICODE

    Hi Gurus,
    How to determine whether the file is a UNICODE format or not?
    I have the file stored as a BLOB column in a table
    Thanks,
    Sombit

    That's a rather hard problem. You would, realistically, either have to make a bunch of simplifying assumptions based on the data or you would want to buy a commercial tool that does character set detection.
    There are a number of different ways to encode Unicode (UTF-8, UTF-16, UTF-32, USC-2, etc.) and a number of different versions of the Unicode standard. UTF-8 is one of the more common ways to encode Unicode. But it is popular precisely because the first 127 characters (which is the majority of what you'd find in English text) are encoded identically to 7-bit ASCII. Depending on the size and contents of the document, it may not be possible to determine whether the data is encoded in 7-bit ASCII, UTF-8, or one of the various single-byte character sets that are built off of 7-bit ASCII (ISO 8859-15, Windows-1252, ISO 8859-1, etc).
    Depending on how many different character sets you are trying to distinguish between, you'd have to look for binary values that are valid in one character set and not in another.
    Justin

  • How to determine the maximum allowable length of a filename for Window ?

    Hi all,
    Could I know how to determine the allowable file length (the length of the absolute path) for a file in Window environment?
    Due to some reason, I generated a zip file with a very long filename ( > 170) and put in a folder(the length of the folder path around 90). The length of the absolute path is around 260.
    I used FileOutputStream with the ZipOutputStream to write out the zip file. Everything is working fine while i generating the zip file.
    However, while i try to extract some files from the zip file i just created, i encountered the error
    java.util.zip.ZipException The filename is too long.
    I am using the class ZipFile to extract the files from the zip file like the following
    String absPath = "A very long filepath which exceed 260";
    ZipFile zipF = new ZipFile(absPath);  //<-- here is the root causeIs it possible to pre-determine the maximum allowable filepath length prior i generate the zip file ? This is weird since i got no error while i created the zip file, but have problem in extracting the zip file ......
    Thanks

    Assuming you could determine the max, what would you do about it? I'd say you should just assume it will be successful, but accommodate (handle) the possible exception gracefully. Either way you're going to have to handle it as an "exception", whether you "catch" an actual "Exception" object and deal with that, or manually deal with the length exceeding the max.

Maybe you are looking for