Win a copy of Practice Tests for OCP Java 17 Certification Exam (1Z0-829) this week in the OCPJP forum!
    Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

append to a text file at the end of the week

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hi,
I am writing a Java program which reads messages off of a queue and then formats the data and has to store this data in a text file,whenever my program runs it has to append to the text file already opened for that week and then it has to close this text file at the end of the week say on sunday nite @ 12.00pm and reopen a new text file @ 12.01am monday and start writing and appending to that file for that whole week and so on..
Any idea how to do this?
Any help appreciated.
Thanks.
Ann
I am attaching a copy of my code I have worked on so far,I am not sure where to append the msgs coming off a queue.
***************************************************
public class MQGet
{
public static void main(String[] args)
{
MQQueueManager MQQueueManager;
boolean forever = true;
try
{
MQQueueManager qMgr = new MQQueueManager(mqManager);
int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT;
MQQueue mqQ = qMgr.accessQueue(mqQname, openOptions);
MQMessage retrievedMessage = new MQMessage();
MQGetMessageOptions gmo = new MQGetMessageOptions();
gmo.options = MQC.MQGMO_WAIT | MQC.MQGMO_FAIL_IF_QUIESCING
| MQC.MQGMO_NO_SYNCPOINT | MQC.MQGMO_ACCEPT_TRUNCATED_MSG;
gmo.waitInterval = 10000;
while (forever)
{
String outString = "";
int msgLen = 0;
retrievedMessage.messageId = MQC.MQMI_NONE;
retrievedMessage.correlationId = MQC.MQCI_NONE;
mqQ.get(retrievedMessage, gmo);
msgLen = retrievedMessage.getMessageLength();
outString = retrievedMessage.readString(msgLen);
System.out.println(msgLen);
if (retrievedMessage.getMessageLength() != 0)
{
String f0 = outString.substring(0,8);
String f1 = outString.substring(8,14);
String f14 = outString.substring(67,(msgLen+1));
f15 = fo + f1 + f14;
System.out.println(f15);
}
else
{
System.out.println(" No Messages available on Queue ");
}
class OpenSundayTextFile
{
FileWriter fw;
public OpenSundayTextFile() throws IOException
{
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
Calendar cal = Calendar.getInstance();
if(cal.get(Calendar.DAY_OF_WEEK) == 1)cal.add(Calendar.DATE,-7);
cal.add(Calendar.DATE,-cal.get(Calendar.DAY_OF_WEEK)+2);
String fileName = sdf.format(cal.getTime()) + ".txt";
fw = new FileWriter(fileName,true);
doSomething();
goodBye();
}
public void doSomething() throws IOException
{
fw.write("f15\r\n");
}
public void goodBye() throws IOException
{
fw.close();
System.exit(0);
}
//This line gives me an error : syntax error on new//
new OpenSundayTextFile();
}
}
mqQ.close();
qMgr.disconnect();
}
*****************
Thanks in adavance
Ann
 
Chicken Farmer ()
Posts: 1932
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Closing this thread since it is being addressed in another one.
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic