This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes I/O and Streams and the fly likes How to reopen a topic for Appending to a textfile. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » I/O and Streams
Reply locked New topic

How to reopen a topic for Appending to a textfile.

Ann Ron

Joined: Oct 21, 2003
Posts: 24
Hi Jason,
I am restarting this thread since it wasn't addressed anywhere.I had posted this topic on the General forum since no one had responded here and someone moved it to the IO forum.and you closed it in this forum assuming it was being addressed there.Can you reopen this topic for discussion.I would really appreciate it if someone could help me with my Java problem.
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.
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;
MQQueueManager qMgr = new MQQueueManager(mqManager);
MQQueue mqQ = qMgr.accessQueue(mqQname, openOptions);
MQMessage retrievedMessage = new MQMessage();
MQGetMessageOptions gmo = new MQGetMessageOptions();
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);
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(" 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);
String fileName = sdf.format(cal.getTime()) + ".txt";
fw = new FileWriter(fileName,true);
public void doSomething() throws IOException
public void goodBye() throws IOException
//This line gives me an error : syntax error on new//
new OpenSundayTextFile();
Thanks in adavance

Posts: 20 | Registered: Oct 2003 | IP: Logged

jason adam
Chicken Farmer (bartender)
Member # 13166
posted December 05, 2003 12:31 PM
Closing this thread since it is being addressed in another one.
Oh the cow in the meadow goes "moo"
Oh the cow in the meadow goes "moo"
Then the farmer hits him on the head and grinds him up
And that's how we get hamburgers.
Nowwwww chickens!
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
Ann - your original thread is now here. You don't need to re-open it - just post your additional questions/comments in the thread. Yes, the one that's here. Creating two more threads about it is just confusing. Thanks.

"I'm not back." - Bill Harding, Twister
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: How to reopen a topic for Appending to a textfile.
Similar Threads
append to a text file at the end of the week
MQ: MQException: Completion Code 2, Reason 2033
Help With Simple Java MQ Connection?
problem in reading message for IBM MQ series using IBM MQ classes
How to append to a text file for a week