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_Provi ders.txt") ;
PrintWriter out1 = new PrintWriter(new FileWriter(f));
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_Provi
PrintWriter out1 = new PrintWriter(new FileWriter(f));
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
do i need a special library for the "new Properties()" argument
just use the util package
java.util.Properties
java.util.Properties
This is also one way to do...using properties to read from a config file..
use this method to generate seqno...append this seq no to ur filename for every request
for example "urfilename"+getSequenceNo
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("getSequenceN
try {
conn = DBUtils.getInstance().getC
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;
}