Append data to same text file using java
Posted
by Manu
on Stack Overflow
See other posts from Stack Overflow
or by Manu
Published on 2010-04-08T10:54:52Z
Indexed on
2010/04/08
11:13 UTC
Read the original article
Hit count: 304
java
SimpleDateFormat formatter = new SimpleDateFormat("ddMMyyyy_HHmmSS");
String strCurrDate = formatter.format(new java.util.Date());
String strfileNm = "Customer_" + strCurrDate + ".txt";
String strFileGenLoc = strFileLocation + "/" + strfileNm;
String Query1="select '0'||to_char(sysdate,'YYYYMMDD')||'123456789' class_code from dual";
String Query2="select '0'||to_char(sysdate,'YYYYMMDD')||'123456789' class_code from dual";
try {
Statement stmt = null;
ResultSet rs = null;
Statement stmt1 = null;
ResultSet rs1 = null;
stmt = conn.createStatement();
stmt1 = conn.createStatement();
rs = stmt.executeQuery(Query1);
rs1 = stmt1.executeQuery(Query2);
File f = new File(strFileGenLoc);
OutputStream os = (OutputStream)new FileOutputStream(f,true);
String encoding = "UTF8";
OutputStreamWriter osw = new OutputStreamWriter(os, encoding);
BufferedWriter bw = new BufferedWriter(osw);
while (rs.next() ) {
bw.write(rs.getString(1)==null? "":rs.getString(1));
bw.write(" ");
}
bw.flush();
bw.close();
} catch (Exception e) {
System.out.println(
"Exception occured while getting resultset by the query");
e.printStackTrace();
} finally {
try {
if (conn != null) {
System.out.println("Closing the connection" + conn);
conn.close();
}
} catch (SQLException e) {
System.out.println(
"Exception occured while closing the connection");
e.printStackTrace();
}
}
return objArrayListValue;
}
The above code is working fine. it writes the content of "rs" resultset data in text file
Now what i want is ,i need to append the
the content in "rs2" resultset to the "same text file"(ie . i need to append "rs2" content with "rs" content in the same text file)..
© Stack Overflow or respective owner