determining cd rom's drive letter in forms 6i [message #365086] |
Wed, 10 December 2008 22:31  |
salman2k960
Messages: 12 Registered: September 2005
|
Junior Member |
|
|
salam
Problem:
I want to determine drive letter of the first CD-ROM installed.
Details:
On a form, i have supplied a browse button to open a file using "GET_FILE_NAME". what i want is that file chooser dialog box should open showing Cd-Rom files(i.e CD-ROM as default location to look for files).
I have tried to do this using Java stored procedure with following class, but somehow, im getting NULLPOINTEREXCEPTION.
CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED "GETDRIVETYPE" AS
import java.io.*;
import javax.swing.*;
import javax.swing.filechooser.*;
class GetDriveType {
public static String GetCdDrive()
{
JFileChooser chooser = new JFileChooser();
String fileTypeName= new String("no drive");
File file[] = File.listRoots();
for (int i=0;i<file.length;i++)
{
if (chooser.getTypeDescription(file[i]).equals("CD Drive"))
fileTypeName= file[i].toString();
}
return fileTypeName;
}
}
This code runs perfectly in JDK, and even gets compiled in Oracle as well. but it gives error at runtime when it tries to execute the line:
JFileChooser chooser = new JFileChooser();
i have read somewhere on OTN that oracle JVM does not support swing or awt and that some HEADLESS awt has been added. But im still unable to find any solution.
Another code that i have tried is:
CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED "GETDRIVETYPE" AS
import java.io.*;
import javax.swing.*;
import javax.swing.filechooser.*;
class GetDriveType {
public static String GetCdDrive()
{
FileSystemView fsv = FileSystemView.getFileSystemView();
String fileTypeName= new String("no drive");
File file[] = File.listRoots();
for (int i=0;i<file.length;i++)
{
if (fsv.getSystemTypeDescription(file[i]).equals("CD Drive"))
fileTypeName= file[i].toString();
}
return fileTypeName;
}
}
Now amazingly, this code compiles,runs and give results in JDK, but it fails to even compile in Oracle JVM!!! it gives error
Method getSystemTypeDescription not found in class javax.swing.filechooser.FileSystemView
this probably is because of some jdk version diff.(btw,im using oracle 9i r2)
My only workaround is to use following VB script to write cd rom letter to a file and then reading it from that file.
Dim CDPath as String
Private Sub Form_Load()
Dim fso As New Scripting.FileSystemObject
Dim drv As Drive
For Each drv In fso.Drives
If drv.DriveType = 4 Then
CDPath = drv.Path
Exit For
End If
Next drv
Set drv = Nothing
Set fso = Nothing
End Sub
Is there any way to do this in forms 6i?
Looking forward for response.
[EDITED by LF: applied [code] tags instead of (the original) [i] (italic) tags]
[Updated on: Thu, 11 December 2008 00:14] by Moderator Report message to a moderator
|
|
|
|
|
|
|
|