https://issues.apache.org/bugzilla/show_bug.cgi?id=44498
--- Comment #1 from Josh Micich <[EMAIL PROTECTED]> 2008-02-28 01:36:40 ---
The functionality you are describing seems to be outside of POI.
I can get a similar exception to the one you are describing to be thrown from
java.io.FileOutputStream.open():
java.io.FileNotFoundException: \\192.168.1.13\share\temp\netExcelFile.xls (The
process cannot access the file because it is being used by another process)
and
java.io.FileNotFoundException: c:\temp\localExcelFile.xls (The process cannot
access the file because it is being used by another process)
I did a few tests, and I get the same error regardless of whether the the file
is on local disk, or on a network share. (For reference, I am using Sun JDK
1.4 on WinXP. The local drive was NTFS, the share was SMB. I called
CreateFile() from the locking process with parameter dwShareMode =
FILE_SHARE_READ).
Just to be sure I checked the JDK(6) source, and there seems to be no evidence
there of differing behaviour for shares vs local files.
My guess is that the differing behaviour is caused by whatever application has
the file open. I tried running the same java code with Excel 2007 holding the
files open, but in _neither_ case was an exception thrown. Java could write to
either file even though Excel had them open. Which application are you using?
>From what I can see, java doesn't provide any easy way to detect if another
process has locked a file. I found that a call to CreateFile( ,
FILE_ALL_ACCESS, 0, , , , ) reliably detects whether another app (including
Excel) has the file open. You could try some native code like the following:
-- FileLockChecker.java:
package example.io;
class FileLockChecker {
public static boolean attemptFullAccess(File f) { ... }
private static boolean attemptFullAccess0(String fileName);
}
-- FileLockChecker.c:
JNIEXPORT boolean JNICALL Java_example_io_FileLockChecker_attemptFullAccess0
(JNIEnv *env, jclass, jstring jstrFileName) {
// convert java string to char*
int len = env->GetStringUTFLength(jstrFileName);
jboolean isCopy;
const char* tempStr = env->GetStringUTFChars(jstrFileName, &isCopy);
char fileName[MAX_PATH+1];
strcpy(fileName, tempStr);
if(isCopy == JNI_TRUE) {
env->ReleaseStringUTFChars(jstrFileName, tempStr);
}
HANDLE hf = CreateFile(fileName, FILE_ALL_ACCESS, 0, NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, NULL);
if(hf == INVALID_HANDLE_VALUE) {
return JNI_FALSE
}
CloseHandle(hf);
return JNI_TRUE;
}
-- -- -- --
Hope this helps somewhat.
--
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]