Create a file if another file exist

I need to create files from a page. I know how to create it, but every request needs to have its own file with a progressive number at the final. Like the following:

if (fileN exist)
create fileN+1

I use the next code to create the file:

File f = new File("/Program Files/Apache Group/Tomcat 4.1/webapps/ROOT/New_Providers.txt");
PrintWriter out1 = new PrintWriter(new FileWriter(f));
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

use this method to generate seqno...append this seq no to ur filename for every request
for example "urfilename"+getSequenceNo("REQ");

      int getSequenceNo(String seqName) throws SQLException, NamingException {
            String newLeadNoSQL = "select " + seqName + ".nextval from dual";

            Connection conn = null;
            Statement stmt = null;
            ResultSet rs = null;

            int seqNo = 0;
            logger.debug("getSequenceNo query :" + newLeadNoSQL);

            try {
                  conn = DBUtils.getInstance().getConnection();
                  stmt = conn.createStatement();

                  rs = stmt.getResultSet();

                  if (
                        seqNo = rs.getInt(1);
                        throw new SQLException("Cant get next seq no from " + seqName);

            } catch (SQLException e) {
                  throw e;
            } finally {
                  try {
                        if (rs != null)
                  } catch (Exception e) {
                  try {
                        if (stmt != null)
                  } catch (Exception e) {
                  try {
                        if (conn != null)
                  } catch (Exception e) {
            return seqNo;
Above code will require for you to create a Database and store the number there.. I think you want to work it out with files only..

You should create a file in your System say
initially it should have following line
then in jsp put following code..

fileProperties = new Properties();
fileProperties.load(new FileInputStream("/Program Files/Apache Group/Tomcat 4.1/webapps/")));

String  number = fileProperties.getProperty("NextNumber");

Now you can use this number to append in your file names..

After you have created your files you shd have following code..
int nextNum = new Integer(number).intValue()+1;

This should work for you

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mmarthaAuthor Commented:
do i need a special library for the "new Properties()" argument
just use the  util package
This is also one way to do...using properties to read from a config file..
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.