This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell 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


JavaRanch » Java Forums » Java » I/O and Streams
Reply locked New topic
Author

How to reopen a topic for Appending to a textfile.

Ann Ron
Greenhorn

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.
Thanks,
Ann
****************************************************************
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

--------------------------------------------------------------------------------
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
Wanderer
Sheriff

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
 
GeeCON Prague 2014
 
subject: How to reopen a topic for Appending to a textfile.