S
sharat
Hi ,
I facing problem while writing into file..
For my problem, File path withh be available after some time. So to
avoide "File does not exist " error I am sleeping in a loop for some
time ana again try to open a file. If file open successfully I will
write into file else through an exception.
If flow enters into while loop , and got the file after Sleep for few
seconds then problem is comeing ..
Failed to write to File: Result is too large"
where as if it does not go into while loop then it is able to create
file and write into it...
I am unable to find the reason. Can anybody help please???
Sample code :
int retryLoopCount = 0;
ofstream myfile;
myfile.open ((const char*)filePath);
while(! (myfile.is_open()))
{
Sleep( (retryLoopCount*2+1)*1000);
if(retryLoopCount++ > RETRY_COUNT)
{
int erCode = errno;
err.Format ("Failed to open file '%s' for writing: %s"
, (const char*)filePath
, strerror(erCode)
);
myfile.close();
throw Exception ------ (// throw Exception -- - I have not copied
the exact sample code here)
}
myfile.open ((const char*)filePath);
}// while retry.
myfile<< (const char*)content;
if (myfile.bad() ) {
int erCode = errno;
err.Format ("Failed to write file '%s': %s"
, (const char*)filePath
, strerror(erCode)
);
myfile.close();
throw Exception ----- (// throw Exception here -- I have not copied
the exact sample code here )
}
myfile.close();
I facing problem while writing into file..
For my problem, File path withh be available after some time. So to
avoide "File does not exist " error I am sleeping in a loop for some
time ana again try to open a file. If file open successfully I will
write into file else through an exception.
If flow enters into while loop , and got the file after Sleep for few
seconds then problem is comeing ..
Failed to write to File: Result is too large"
where as if it does not go into while loop then it is able to create
file and write into it...
I am unable to find the reason. Can anybody help please???
Sample code :
int retryLoopCount = 0;
ofstream myfile;
myfile.open ((const char*)filePath);
while(! (myfile.is_open()))
{
Sleep( (retryLoopCount*2+1)*1000);
if(retryLoopCount++ > RETRY_COUNT)
{
int erCode = errno;
err.Format ("Failed to open file '%s' for writing: %s"
, (const char*)filePath
, strerror(erCode)
);
myfile.close();
throw Exception ------ (// throw Exception -- - I have not copied
the exact sample code here)
}
myfile.open ((const char*)filePath);
}// while retry.
myfile<< (const char*)content;
if (myfile.bad() ) {
int erCode = errno;
err.Format ("Failed to write file '%s': %s"
, (const char*)filePath
, strerror(erCode)
);
myfile.close();
throw Exception ----- (// throw Exception here -- I have not copied
the exact sample code here )
}
myfile.close();