Link to home
Start Free TrialLog in
Avatar of mmartha
mmartha

asked on

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:

request
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));
Avatar of vikraman_b
vikraman_b

Hi,
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();

                  stmt.execute(newLeadNoSQL);
                  rs = stmt.getResultSet();

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

            } catch (SQLException e) {
                  throw e;
            } finally {
                  try {
                        if (rs != null)
                              rs.close();
                  } catch (Exception e) {
                  }
                  try {
                        if (stmt != null)
                              stmt.close();
                  } catch (Exception e) {
                  }
                  try {
                        if (conn != null)
                              conn.close();
                  } catch (Exception e) {
                  }
            }
            return seqNo;
      }
ASKER CERTIFIED SOLUTION
Avatar of Kuldeepchaturvedi
Kuldeepchaturvedi
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 mmartha

ASKER

do i need a special library for the "new Properties()" argument
just use the  util package
java.util.Properties
This is also one way to do...using properties to read from a config file..