Win a copy of Head First Android this week in the Android forum!

Melynda Coxx

Greenhorn
+ Follow
since Jan 30, 2002
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Melynda Coxx

Yeah..., but if you will remember my initial objective, canWrite() doesn't do what I need because OS pops up the dialog...
I agree with you, Rob, that not having any system-specific stuff would be more desirable, but it actually isn't as bad in this case because the overall package that this is a part of happens to already need to determine the OS-filesystem type (Windows or Unix) in order to determine whether the 'FS root' is '/' or a collection of drive letters. AND my company's SW is supported only on specific versions of these two, so I can rightfully puke if I find anything out of place.
This thread is certainly still open to anyone who can find a (better) way to see if floppy\blah directory exists without having the Abort|Retry|Ignore dialog... I am still curious to see some of the amazing hacks that folks can dream up.
Melynda
19 years ago
I was coming back to answer my own post, because I found a solution in the meantime.
But since someone has answered in the meantime, let me first add that I did come across people who could run code like mine and the above suggestion on their NT machines without that dialog popping up, and others who got the dialog... (leads me to speculate that it might be an OS setting or version thing, I dunno...)
My case was that no matter what member method from the File class I called, I couldn't access or see-if-I-could-access without getting the dialog, including canRead() and canWrite().
An ingenius solution that someone suggested worked for me though, and I wanted to share the wealth with this group:
After I determine I am on a windows system and that A: is a root, I do a Runtime.exec() call to "cmd.exe /c dir a:", then when I try a read on the stream, the read returns null if there is no disk. (And the output from dir if there is a disk).. the empty drive rumbles for a moment, but NO DIALOG!
Resolved, and thanks.
19 years ago
(I also posted this question in I/O forum...)
I am writing a program in which I would like to quietly "look ahead" whether a directory exists or is available.
I am only trying to see IF a directory/file is available; I don't want to alarm my user if it is not.
The problem I am having with this is that when I run this on WindowsNT to look into the (potentially available) subdirectories on the floppy disk when there is not physically a disk in the drive, I get the operating system's nice dialog popup that says "There is no disk in the drive. Please insert a disk into drive A:. Abort|Retry|Ignore".
The method I am using to "peek" is
- call the static File.listRoots(), which indicates that "A:" is a valid drive.
- With my File object for the "A:\"drive, any kind of access I try...
.isDirectory()
.exists()
.listFiles()
new FileInputStream(File)
etc.
gives me the offensive dialog...
I am seeking a method/alogrithm to see what's there, or whether the A-drive is available, by finding a method that QUIETLY (via exception or return value) attempts access without causing the OS to pop up that irritating dialog.
Has anyone had experience with something like this? Thank you so much if you can help me out.
--
Mel
19 years ago
Reverse the order of your 3 close calls. They are backwards...
i.e. change

to

It worked for me.
Mel
[ January 31, 2002: Message edited by: Melynda Coxx ]
19 years ago
See, I AM a greenhorn!
My code above lost its spacing. (Sorry it looks terrible.)
I just now noticed the CODE button down below...
Mel
19 years ago
Hi,
I haven't done exactly what you are describing, but recently I did something similar -- looking to see if a method (rather than a field) was available.
I don't know whether this is the best way to do this. I figured it out myself, so it is probably not the most efficient way. I am curious myself to see how others might reply to your question.
Let me first explain what I was trying to do and then show my code snippet:
There were two versions of a class I was using called ProxyPort. The later version of ProxyPort had changed its disconnect() method from private to public. I wanted to call disconnect() if it was available, so I did a check to see if it was available using the File.getDeclaredMethod() method. (You may be able to use the File.getDeclaredField() method in a similar fashion.)
// a class field:
private ProxyPort proxyPort;
...
// the method:
private void invokeDisconnectIfAvailable()
{
Class proxyPortClass = proxyPort.getClass();
java.lang.reflect.Method disconnectMethod = null;
try
{
disconnectMethod = proxyPortClass.getDeclaredMethod("disconnect",new Class[0]);
}
catch(NoSuchMethodException e)
{
return; // nothing we can do
}
int modifiers = disconnectMethod.getModifiers();
if (! java.lang.reflect.Modifier.isPublic(modifiers))
return; // can't call it
try
{
disconnectMethod.invoke(proxyPort,new Object[0]);
}
catch(IllegalAccessException e)
{} // oh well we tried
catch(java.lang.reflect.InvocationTargetException e)
{} // oh well we tried
} // end invokeDisconnectIfAvailable()
Hope this helps,
Mel
[ January 30, 2002: Message edited by: Melynda Coxx ]
19 years ago
I am writing a program in which I would like to quietly "look ahead" whether a directory exists or is available.
I am only trying to see IF a directory/file is available; I don't want to alarm my user if it is not.
The problem I am having with this is that when I run this on WindowsNT to look into the (potentially available) subdirectories on the floppy disk when there is physically disk in the drive, I get the operating system's nice dialog popup that says "There is no disk in the drive. Please insert a disk into drive A:. Abort|Retry|Ignore".
The method I am using to "peek" is
- call the static File.listRoots(), which indicates that "A:" is a valid drive.
- With my File object for the "A:\"drive, any kind of access I try
.isDirectory()
.exists()
.listFiles()
new FileInputStream(File)
etc.
gives me the offensive dialog...
I am seeking a method/alogrithm to see what's there, or whether a-drive is available, by finding a method that QUIETLY (via exception or return value) attempts access without causing the OS to pop up that irritating dialog.
Has anyone had experience with something like this? Thank you so much if you can help me out.
19 years ago