File.exists() doesn't work

Hi, this seems really weird to me. I cannot make this simple code work. Here is what and how.
I have index.jsp which includes checkFile.jsp. This checkFile checks for existance of the file in the directory.
index.jsp is in the main directory. checkFile.jsp and the files to check are in the directory "data".
Code in index.jsp:
<%
String incFile = reuqest.getParameter("data");
incFile = incFile + ".htm"
%>
<%@ include file="data/checkFile.jsp"%>
Code in checkFile.jsp
<%
boolean f_exists = false;
File f = new File(incFile);
     if(f.exists()){
          f_exists = true;
%>
The result I get: f_exists is false. How come? Please, people, this is a quick and easy question, right?
Cheers,
Alex
P.S. It is Win2KPro, Tomcat 3.3.

You probably are assuming you know what directory your path "data/checkFile.jsp" is relative to, and you are probably assuming incorrectly. Try the getAbsolutePath() method of your File object to see what you are actually checking.
By the way, the code you have there:boolean f_exists = false;
File f = new File(incFile);
if(f.exists()){
  f_exists = true;
}is not wrong, but could be written asFile f = new File(incFile);
boolean f_exists = f.exists();

Similar Messages

  • When i convert a word file with a hyperlinks to a PDF file it doesn't work ?? thanks in advance for helping me

    when i convert a word file with a hyperlinks to a PDF file it doesn't work ?? thanks in advance for helping me

    using microsoft word.
    the hyperlink doesn't work in the pdf file (adobe reader).
    adobe reader xi.
    my operating system windows 8.1.
    the attached screen is appeared.

  • File.delete() and File.deleteOnExit() doesn't work consistently..

    I am seeing some odd behavior with trying to delete files that were opened. Usually just doing new File("file.txt").delete() would work. However, in this case, I have created an input stream to the file, read it in, saved it to another location (copied it), and now I am trying to delete it.
    The odd thing is, in my simple application, the user can work with one file at a time, but I move "processed" files to a lower pane in a swing app. When they exit it, it then archives all the files in that lower pane. Usually every file but the last one opened deletes. However, I have seen odd behavior where by some files don't delete, sometimes all of them wont delete. I tried the deleteOnExit() call which to me should be done by the JVM after it has released all objects such that they don't matter and the JVM ignores any object refs and directly makes a call (through JNI perhaps) to the underlying OS to delete the file. This doesn't work either.
    I am at a loss as to why sometimes some files delete, and other times they don't. In my processing code, I always close the input stream and set its variable to null. So I am not sure how it is possible a reference could still be held to the object representing the file on disk.

    and then, in the other class
      public int cdplayerINIToMMCD(File aDatabase, String thePassword) throws IllegalArgumentException {
         /*---------DATA---------*/
         String dbLogin, dbPassword;
         JFileChooser fc;
         INIFileFilter ff;
         int dialogReturnVal;
         String nameChosen;
         File INIFile;
         ProgressMonitor progressMonitor;
         BufferedReader inFileStream;
         String oneLine;
         int totalLines = 0;
         int linesParsed = 0;
         boolean openDBResult;
         int hasPassword;
         if ((aDatabase == null) || (!aDatabase.exists()) ||
            (FileManagement.verifyMMCD(aDatabase) == FileManagement.VERIFY_FAILED)) {
            throw new IllegalArgumentException();       
         else { 
            currentDB = aDatabase;
            if(thePassword == null) {
              dbPassword = "";
            else { dbPassword = thePassword; }
            dbLogin = dbPassword; //For MSAccess dbLogin == dbPassword
         //Ask the user for the cdplayer.ini file.
         //Create a file chooser
         if (System.getProperty("os.name").indexOf("Windows") > -1) {
            fc = new JFileChooser("C:\\Windows");
         else {
            fc = new JFileChooser();     
         fc.setMultiSelectionEnabled(false);
         fc.setDragEnabled(false);
         //Create a new FileFilter
         ff = new INIFileFilter();
         //Add this filter to our File chooser.
         fc.addChoosableFileFilter(ff);
         fc.setFileFilter(ff);
         //Ask the user to locate it.
         do {
            dialogReturnVal = fc.showOpenDialog(mainFrame);
            if (dialogReturnVal == JFileChooser.APPROVE_OPTION) {
               nameChosen = fc.getSelectedFile().getAbsolutePath();
               if(nameChosen.toLowerCase().endsWith(INIFileFilter.FILE_TYPE)) { INIFile=new File(nameChosen); }
               else { INIFile = new File(nameChosen+INIFileFilter.FILE_TYPE); }
               if (!INIFile.exists()) {
                  continue; //If the name specified does not exist, ask again.
               else { break; }
            else { //User clicked cancel in the open dialog.
               //Ignore what we've done so far.
               return(IMPORT_ABORTED);
         } while(true); //Keep asking until cancelled or a valid file is specified.
         //Determine how many lines will be parsed.
         try {
           //Open the INI for counting
           inFileStream = new BufferedReader(new InputStreamReader(new FileInputStream(INIFile)));
           while ((inFileStream.readLine()) != null) {
               totalLines++;
           //Close the INI file.
           inFileStream.close();
         } catch (IOException ex) { return(IMPORT_FAILED); }
         //Make a progress monitor that will show progress while importing.
         progressMonitor = new ProgressMonitor(mainFrame, "Importing file","", 0, totalLines);
         progressMonitor.setProgress(0);
         progressMonitor.setMillisToPopup(100);
         progressMonitor.setMillisToDecideToPopup(1);
         //Make our DatabaseHandler to insert results to the database.
         dbh = new DatabaseHandler();
         //Open the database connection.
         do {
           try {
              openDBResult = dbh.openDBConnection(currentDB, dbLogin, dbPassword);
           } catch(JDBCException ex) { return(IMPORT_JDBC_ERROR); } //OUCH! can't write anything.
             catch(SQLException ex) {
                 openDBResult = DatabaseHandler.OPNCN_FAILED;
                 //Can not open the database. Is it password protected?
                 hasPassword = JOptionPane.showConfirmDialog(mainFrame, "Could not open the database. "+
                                                "The password is wrong or you have not specified it.\n"+
                           "Do you want to enter one now?", "New password?", JOptionPane.YES_NO_OPTION);
                if (hasPassword == MMCDCatalog.DLG_OPTN_YES) {
                   dbPassword = JOptionPane.showInputDialog(mainFrame, "Please enter your "+
                                                              "password for the DataBase:");
                    dbLogin = dbPassword; //For MSAccess, login == password                                                    
                //If the password wasn't the problem, then we can't help it.
                else { return(IMPORT_FAILED); }
         } while(openDBResult != DatabaseHandler.OPNCN_OK); //If it is OK, no exception thrown.
         //Import the ini file
         try {
            //Open the INI file for parsing.
            inFileStream = new BufferedReader(new InputStreamReader(new FileInputStream(INIFile)));
            //Read and parse the INI file. Save entries once parsed.
            while ((oneLine = inFileStream.readLine()) != null) {
               parseLine(oneLine);
               linesParsed++;
               progressMonitor.setNote("Entries imported so far: "+entriesImported);
               progressMonitor.setProgress(linesParsed);
               if ((progressMonitor.isCanceled()) || (linesParsed == progressMonitor.getMaximum())) {
                  progressMonitor.close();
                  break;
            //Close the INI file.
            inFileStream.close();
         } catch (IOException ex) {
              //Make absolutely sure the progressMonitor has disappeared
                progressMonitor.close();
                if (dbh.closeDBConnection() != DatabaseHandler.CLSCN_OK) {
                 JOptionPane.showMessageDialog(mainFrame, "Error while reading the INI file.\n"+
                    "Error while attempting to close the database", "Error", JOptionPane.INFORMATION_MESSAGE);
              else {
                 JOptionPane.showMessageDialog(mainFrame, "Error while reading the INI file.",
                                                    "Error", JOptionPane.INFORMATION_MESSAGE);     
                return(IMPORT_FAILED);
         //Make absolutely sure the progressMonitor has disappeared
         progressMonitor.close();
         //Close the database connection
         if (dbh.closeDBConnection() != DatabaseHandler.CLSCN_OK) {
            JOptionPane.showMessageDialog(mainFrame, "Error while closing the database after import.",
                                          "Error", JOptionPane.INFORMATION_MESSAGE);
         //Did the user cancel?
         if (totalLines != linesParsed) {
            return(IMPORT_ABORTED);     
         //Success!
         //Everything ok. Return the number of entries imported.
         return(entriesImported);
      }

  • Does file exist isn't work.

    I've been using this script to see if a file exists. The code works fine on everything but vbs files. I can put any other kind of file and it will find it, but a vbs file that I know is there it can't find. Anyone else have problems with this?
            boolean exists = (new File("C:/WINDOWS/system32/prnmngr.vbs")).exists();
           if (exists){
               System.out.println("File is there");
           }else{
                System.out.println("File is not there");
           }

    Works fine for me.
    Maybe you spelled the file name wrong.
    Maybe your Explorer settings are "Don't show system files", and that is a system file and that setting affects a library that Java also uses.
    Maybe the user that you're logged in as doesn't have permissions to see that file.
    File.exists() works, but its behavior is affected by the underlying file system, and that behavior may not always be intuitive.

  • Locate file window doesn't work

    Ok, this problem occures only on our Z800 workstations.
    Everything works as expected on my laptop.
    When I try to relink a media file, the relink media window opens, and then I click the Locate button.
    The new window ALWAYS opens in the top most level (basically My Computer in windows) and not in the last used directory.
    I think it has something to do with the second problem - the path text box doesn't work. Whatever I enter there and click Return - nothing happens. It doesn't navigate to the folder specified in the path field. The only way to navigate is to go throught the folder tree on the left.
    For every file I have to do it always from the top most level - that is a lot of clicking.
    Also if I uncheck Use Media Browser to locate files, the default windows dialog properly navigates to the last known location of the file.
    I know it's an error - since on my laptop everything works fine. The window opens in the last know location of the media file and I can easily navigate using the path field.
    Any suggestions what could be the reason for this?

    Jim Simon wrote:
    I'm not sure if this is a bug.  The Locate File dialog seems to be opening where it thinks the file might be, rather than where it was.  For example, I renamed the 0000.mts file for a particular project, and when I opened Premiere Pro, Locate File went to the 0000.mts file from another project/folder, thinking that might be it.
    So...if you have no other files that might be the missing file, the dialog starts at the top.
    Jim,
    I understand what you are saying in regard to where it thinks it might be. However if I manually type a path where a file I want to link to rathter then clicking 20 times in the folder tree, it throws a "File not accessible" error. Yet if I use the folder tree to navigate to the same file it sees it and links to it fine.
    It just seems that whenever I try to manually type a path in the path address field is when the error occurs.
    Are you able to manually type in a path > hit enter/return and have it link to the file?

  • When my Imac first boots up, file sharing doesn't work

    27" iMac; about 7 months old
    OS X 10.8.4
    2.7 Ghz Intel Core i5
    When I first boot it up, file sharing with the PCs doesn't work.  I have to turn file sharing off then back on, sometimes I have to do it several times, before the PCs will finally connect using their mapped drives.

    Move the com.apple.systempreferences.plist out of the stupidly hidden /Library/Preferences/ folder onto the Desktop, restart, and see if the problem persists. If not, reset your system preferences and delete the moved file. Then, update to 10.8.5.

  • File sharing doesn't work between two computers

    I have a Macbook Air bought late 2009 (I'll call it MBA 1). OS 10.6.0.
    I have a new Macbook Air bought a few days ago (I'll call it MBA 2). OS 10.6.4.
    I have been attempting to share files from the two computers.
    I was able to move files from MBA 1 to MBA 2 without too much fuss. I could do it both ways: by finding "Shared" in Finder and then accessing the files or I could go to "Go" and "Connect to Server". I was able to add the username of the MBA 2 to the list of users in the Sharing pane of the MBA 1.
    So going from MBA 1 ---> MBA 2 is fine.
    However going from MBA 2 ----> MBA 1 doesn't work.
    1) The finder in the MBA 1 doesn't show "Shared".
    2) I can't add user to the Sharing pane of the MBA 2.
    The problem could be that the two usernames of the MBA 1 and the MBA 2 are very similar.
    Username of MBA 1: jk
    Username of MBA 2: J K
    I tested this theory out by adding a username I just made up called "Jack" and it added the username fine to the list of users.
    But it's too late to change the username of the computers now.
    What can I do?

    I got it to work.
    What I did was on MBA 2, I went to "Go" and "Connect to server". Then I selected the MBA 1 to connect to.
    As soon as I did that, "Shared" appeared in Finder with the MBA 2's name on it.
    After connecting which took a long time, the folders to be shared showed up in the Finder window.
    I don't know why trying to connect to MBA 2's server didn't work in MBA 1. I went to "Go" and "Connect to server" many times on the MBA 1 but it didn't work.

  • Custom File Name-Original File Number doesn't work. Why?

    I want to export and rename some files with the "Custom File Name-Original File Number" option. Yet this doesn't seem to work, and I wondered what I might be doing wrong. The filename will only rename as the custom text.
    The sample file name shown underneath has a dash after the custom text bit, but then the extension only eg Newname-.tif
    I am now using LR 4.2 but I seem to remember doing this renaming OK with an earlier version (though I can't remember which). This suggest that either there is a problem with this specific version or that I have something set differently to the way I had it initially. I am hoping the latter is the case. Any suggestions as to how to fix this would be welcome!

    I am sorry to report that i don't know how to create a screenshot. However, what I am getting, exact;ly is this:
    From Library grid view: F2 or Library>Rename Photo
    Then little screen appears with heading Rename Photo:
    File Naming> set to Custom Name - Original File Number
    Custom Text> NewFilenameHere
    Example: NewFilenameHere-.tif
    Clicking on OK changes the filename to just the custom text without the original file number. Original File name shows in metadata eg DSC01129-Edit.tif
    The only way i seem to be able to get the original file number with the custom text is to include it manually as part of the custom text.

  • File sharing doesn't work

    Hi(I'm new to mac)
    I have two computers in my home, one is Windows based desktop computer and the other is macbook air. Both are connected to the same router. Desktop pc is connected via ethernet and macbook air via wifi. As my storage in macbook is just 128Gigs so I used to access my desktop PC's hard disk using network sharing. It all worked fine and was so smooth, I just had to connect to wifi and click on my PC(faran-pc) from the Network and there I go.
    But since last two days it won't connect, all the settings are same, I didn't alter anything. When I click on connect As, it allows me to enter the username and password(I had already given them before when connected for the first time) of the Desktop PC user just like before, but when after entering perfectly correct username and password I click Connect that window just vibrates and nothing happens. I've checked from my pc, file sharing is allowed there, so no security issue. If I disable filesharing from my Desktop it won't ask even for the username and password. Everything is fine with the router too. I don't know why it wont connect.
    What I've tried so far:
    1) Tried to connect manually by entering my Desktop name/IP address(smd://faran-pc or smd://ipaddress), but it stucks at the same place.
    2)I deleted my keychain data stored for this server, still no luck.
    3)Tried to connect from my Desktop to my Laptop, it connects from there, but doesn't allow me to copy bigger file like of few gigs from my desktop to mac.
    4)Tried changing the username and password of the desktop computer as well.
    5)Tried to connect through guest too.
    6)Deleted network/dns cache by using -flushcache in terminal.
    I don't know what to do, can't find out any other possible solution. Attaching some of the screen shots.

    Rebooted both computers, and router many times.
    Turned all three of them off for 15 minutes and then turned on, no luck.

  • Reduce File Size doesn't work!

    When I click the (new) option 'Reduce File Size' in Keynote '09 the app prompts a estimated new size which is smaller than the current size. When I click on 'Reduce' the app doesn't do anything except for showing an error report which tells me something like: "..the file size was not reduced", for all of the files included. They are just regular .jpg/.png and .psd files. Did anyone else notice this bug..?

    PeterBreis0807 wrote:
    I'd say if it is a very large file with multiple large images, it might not be actually freezing, just taking its sweet time.
    It's why I leave Activity Monitor running when I use iWork applications.
    This way, I know ifd the app is dead or if it's heavily busy.
    Either that or it has nothing to do. It trims and reduces the resolution of bitmap images to 72dpi. There will be a fair bit of work if you have transparency in the document.
    It doesn't do a very good job IMHO and to reduce the file by 90% is a big ask.
    The 'Reduce FileSize' feature isn't linked to the 'export to PDF' feature.
    As explained, before applying "Reduce file size" it's good practice to "Reduce Image File Size".
    This will drop the parts of the pictures which aren't displayed.
    The asked task doesn't imply a reduction of the pictures by 90%.
    As I already wrote several times, it's more efficient to crop images to the really used area *_before inserting them in a Pages document_*.
    A Pages document is huge by nature because the Index.xml file describing its contents is highly verbose.
    If the document was saved with the 'embed Preview.pdf' feature active, the size of this PDF is adding a lot of used space.
    I'd print to pdf and reduce the quality in Acrobat Pro.
    Most of us don't own Acrobat Pro.
    I feel that it would be a bit silly to buy an application whose price is : 450$ as a complement for a 80$ set of applications.
    Before doing that, I would
    (a) crop pictures before inserting them
    (b) try to enhance Pages behaviour for free installing enhanced PDF filters.
    Yvan KOENIG (VALLAURIS, France) dimanche 29 août 2010 09:53:44

  • File.deleteOnExit() doesn't work

    My application generates some temporary files (XML files and copied XSL files). The Apache FOP processor then generates other files (PDF) in a different directory. After processing, my application deletes those temporary files. Howevere, some of those files can't be deleted (File.delete() returned false). I guess, FOP still has some access to them ovene though, i clear my FOP ressources. In those cases, I do a myFile.deleteOnExit(). But this doesn't seem to work: those files never get deleted when i exit the application (and therefore the VM). I have to delete them by hand (and this works).

    Well, I close the files, but i don't know if FOP still has open file handles.
    I also tried to add a shutdown hook to delete the remaining files, but this doesn't help.

  • File.setLastModified doesn't work for files with another owner and 777 perm

    import java.io.File;
    public class Main {
        public static void main(String[] args) {
            File file = new File(args[0]);
            System.out.println("exec:" + file.canExecute());
            System.out.println("read:" + file.canRead());
            System.out.println("write:" + file.canWrite());
          System.out.println(file.setLastModified(System.currentTimeMillis()));
    } Compile it to ~. In ~ create file aaa.txt. Next
    ~ $ sudo chown root:root aaa.txt
    ~ $ sudo chmod 777 aaa.txt Checking
    ~ $ ls -la aaa.txt
    -rwxrwxrwx 1 root root 472 2009-11-24 12:09 aaa.txt Running application
    ~ $ java -Djava.security.debug=all Main /home/jfreem/aaa.txt
    scl:  getPermissions ProtectionDomain  (file:/home/jfreem/ <no signer certificates>)
    sun.misc.Launcher$AppClassLoader@1c78e57
    <no principals>
    java.security.Permissions@1186fab (
    (java.lang.RuntimePermission exitVM)
    (java.io.FilePermission /home/jfreem/- read)
    scl:
    exec:true
    read:true
    write:true
    false setLastModified return false and modification time of file remain the same. Why?

    Can you see if the file is getting to the webserver's (not
    ColdFusion)
    temp file directory?
    When a file is uploaded from the browser the
    webserver(IIS|Apache|etc)
    upload it to a temp location, then all CFFile does is copy
    the file
    from the temp directory to where ever specified.
    So you can see if the problem is failing before or after this
    point.
    Grant wrote:
    >
    >
    > We are migrating our intranet from ColdFusion 5 on
    Solaris to ColdFusion MX 7
    > on Linux and I'm testing out the existing applications
    on the new server. The
    > processing page for a file upload is using CFFILE with
    ACTION="upload". The
    > page finishes processing fine, no error, and continues
    as if it was successful
    > but the file never actually gets to the destination
    directory. I tried with
    > larger files and it did take longer (so the file
    appeared to get transmitted),
    > but it still does not get saved to the server's file
    system. This all works
    > fine on the current system running CF5. I've tried the
    CFFILE destination with
    > and without a slash at the end - no difference. We have
    ColdFusion 7.0.1
    > installed. Hot fix 2 has been applied but that did not
    fix the problem.
    >
    > Any ideas?
    >

  • Gnome 3.8 Files search doesn't work.

    Hello everyone,
    After doing a clean install of Gnome 3.8, and knowing that there is support for "Files" search results, I noticed that no search results are displayed from Files.
    Files is obviously Nautilus and it's index is working with Tracker. I have all the correct locations in Tracker set up (my two Ntfs partitions), Tracker displays the results, but Nautilus won't show anything even if I select the "All files" option.
    If I go to the directory that the disks are mounted, then I get results, even if they are inside a directory, which means that recursive search works.
    It is obvious to me that Gnome-Shell displays the results from the "All Files" query of Nautilus, which is NOT working and it is practically useless.
    Is it like that for you also, or have I screwed up something?
    Thanks in advance

    Yes you're right, it doesn't seem to work. I solved it by creating symlinks to the partitions in the home folder.
    Also, I changed the permissions of the folders I wanted index to rwx so that tracker can index them. Not exactly sure if I had to.
    Last edited by spiritwalker (2013-05-10 22:27:20)

  • "open file" vi doesn't work in executable

    I have built an executable that reads a com port and displays the readings in a chart.
    The vi also has a "start logging" button that uses the "open file", "write to file", and "close file" vi's, and it works on the machine with labview installed on it.
    When saving it as an executable and executing it on a clean PC, I can select the com port, I can see the graph working, and when I start logging, I can select a new filename.
    However after closing the file, and opening it in a text editor, there is nothing in the file.  So I think there is a problem with the "write to file" vi.
    I tried this both in LV 8.5 as well as 7.1 with the same results. Any ideas? I have Visa and Run-time running on the clean PC. Are there any other drivers that I need to run on the host PC?

    You have a lot of problems with your VI:
    Lousy architecture. You have 4 loops. That's 3 too many. You only need one loop. The code that does the data logging should be in the main (and only) loop.
    Do not open and close VISA sessions every time you iterate. Open once. Close once.
    Do not open and close files every time you iterate. Open once. Close once.
    You do not need to write to an indicator and to a local variable at the same time. A local variable is not a separate entity from a control/indicator - it's the same thing. Thus, the write of the local variable is superfluous. Besides, if you were to correctly code this to use only one loop you wouldn't need the local variable in the first place.
    Why are you creating dynamic data from a set of 4 floating point values? Use Build Array to create an array. Charts and graphs do not require you to use dynamic data.
    Identical labels. You have four controls called "Current Temp °C". If I mentioned the "Current Temp °C" control, would you know which one I'm talking about? Make your labels distinct. Use captions if you want the text on the front panel to say the same thing. 
    I don't know if that serial stuff is a by-product of you opening an old VI in 8.5, so I don't know what that SetSerialTermChar VI is supposed to be. You should look at the serial port examples that ship with LabVIEW for updated VIs.
    That's it for now....

  • Personal File sharing doesn't work

    I'm trying to transfer files from my G4 to my G5.
    I've been successful until now.
    All of a sudden my G4 will not allow me to enable Personal File Sharing.
    I click the "Start now" button, and nothing.
    I have also been having start-up and sleep problems as well as mouse cursor disappearing after sleep mode. Could they all be related?

    I'm using a Network cable on the G4.
    Airport card on the G5.
    Aftermarket wireless G router.
    As I said it worked fine just hours before. Now won't network at all.
    I'm using an Apple USB mouse.
    G4 will sometimes just freeze after chime and screen will not come up, or comes up very slowly. Mouse will often disappear after waking from sleep mode. Or sometimes it will not wake from sleep. I've removed all peripherals except Apple monitor and mouse.

Maybe you are looking for

  • How to use a select list value in a PL/SQL function body returning SQLquery

    Hi Friends, I have a select list P6_TEST with values 'nav' anf 'jyo'. I am trying to create a report using "SQL Query (PL/SQL function body returning SQL query)". In my report query can i check if P6_TEST='nav' and do something like the code shown be

  • Using external drive for itunes

    Hope someone can help with this: I am going travelling and want to take my music library, at present in itunes on my desktop G4. I have copied this library onto a 100GB portable hard drive, and would now like to get itunes on my macbook to refer to t

  • How do I put a drawer in the dock?

    I want to group my applications in the dock into drawers. I keep frequently used programs in the dock to make it quick to open. But I would also like to group (for example all the programs for photos) some applications into one dock space. There are

  • Is there any other way i could block websites on my apple router?

    hello there guys! is there anyway i could block websites on my router apple using airt utility? \Many thanks...

  • How to created a new report in content tracker report?

    Hi I need to created a new report that show who modified the document's metadata and when, but I have never used Content Tracker and I do not know how. Appreciate the help you can give me. Thanks.