Link to home
Start Free TrialLog in
Avatar of gvijay1
gvijay1

asked on

Checking to see existance of a file before creating one.

Experts,

I am creating a servlet where in the Init() method, I am creating a file. however, I need to modify it and am not sure how to do it.

when the servlet is loaded, and the init method called, I need to first check to see if there is an existing file before before creating the file. This is to ensure that I do not overwrite the data from a day before. This is the code that I have currently to create a new file. Could you please modify it to include the logic to check to see if this particular file exists in the given directory before creating it. Thanks,

     //Now to set up the Performance log File initially when the servlet is loaded
     try
     {
          outputFile = new File("/u/iscdev/Performance/Performance.txt");
          out = new RandomAccessFile(outputFile, "rw");
     }
     catch(java.io.IOException e)
     {
              System.out.println(e.toString());
    }
ASKER CERTIFIED SOLUTION
Avatar of Jim Cakalic
Jim Cakalic
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Moondancer
Moondancer

Question(s) below appears to have been abandoned. Your options are:
 
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you. You must tell the participants why you wish to do this, and allow for Expert response.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question. Again, please comment to advise the other participants why you wish to do this.

For special handling needs, please post a zero point question in the link below and include the question QID/link(s) that it regards.
https://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click the Help Desk link on the left for Member Guidelines, Member Agreement and the Question/Answer process.  https://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

Please click you Member Profile to view your question history and keep them all current with updates as the collaboration effort continues, to track all your open and locked questions at this site.  If you are an EE Pro user, use the Power Search option to find them.

To view your open questions, please click the following link(s) and keep them all current with updates.
https://www.experts-exchange.com/questions/Q.20092733.html
https://www.experts-exchange.com/questions/Q.20147918.html
https://www.experts-exchange.com/questions/Q.20168330.html
https://www.experts-exchange.com/questions/Q.20205426.html
https://www.experts-exchange.com/questions/Q.20265649.html
https://www.experts-exchange.com/questions/Q.20266870.html
https://www.experts-exchange.com/questions/Q.20269541.html


To view your locked questions, please click the following link(s) and evaluate the proposed answer.
https://www.experts-exchange.com/questions/Q.20103690.html

PLEASE DO NOT AWARD THE POINTS TO ME.  
 
------------>  EXPERTS:  Please leave any comments regarding your closing recommendations if this item remains inactive another seven (7) days.  Also, if you are interested in the cleanup effort, please click this link https://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643
 
Thank you everyone.
 
Moondancer
Moderator @ Experts Exchange

P.S.  For any year 2000 questions, special attention is needed to ensure the first correct response is awarded, since they are not in the comment date order, but rather in Member ID order.
gvijay1:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
Recommendation: points to jim_cakalic
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

- Points for jim_cakalic

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Venabili
EE Cleanup Volunteer