• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How do i get the drive names

 
Uma Lade
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
whenever i log into some novell server, some folders of the novell server will be mapped to some of my drives. For example I: is mapped \\MRS01\Data. Through java, how do get the drive name? I want retrieve the name of I: as \\MRS01\Data.
I would be very much grateful if somebody can help me out.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18098
50
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can get the basic information about the filesystem by using the java.io.File class to read in the directory you get back from a "new java.io.File("/")" call.
I haven't checked to see how multiheaded filesystems like Windows handles that, but there are ways, and, as far as I'm aware, Sun has allowed for them.
Note, however, that OS-specific file and filesystem information retrieval is not supported by Java, since that would violate the "write once run anywhere" mandate. So in order to find out, for example, how much free space was on a WIndows disk drive, you'd have to use a JNI class.
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's the static java.io.File.getFileRoots() method (I think that's what it's called...) that will return all the root directories of the system. For UNIX, that's just "/", but on Windows it's {C:\, D:\, I:\, etc.}
However, that does not support either obtaining network drives or obtaining the network name of the mapped drive. AFAIK, Java does not support this type of file naming (\\SomeMachine\directory\)
 
george pii
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is a script/class that gets the mapped address on a Wintel machine. It gets the network address that is mapped to drive letter "P:". The loop can be changed to print all maps and lots of other things.

// ============================================================
import java.io.* ;

/**
*
* <P>MappedDriveAddresses.java
* <BR>Created May 14, 2004
* @author George Pii
*/
public class MappedDriveAddresses
{
public static void main(String[] args) throws Exception
{
Runtime runTime = Runtime.getRuntime() ;
Process process = runTime.exec( "net use" ) ;

InputStream inStream = process.getInputStream() ;
InputStreamReader inputStreamReader = new InputStreamReader( inStream ) ;
BufferedReader bufferedReader = new BufferedReader( inputStreamReader ) ;

String line = null ;
String [] components = null ;
while( null != (line = bufferedReader.readLine() ) )
{ //System.out.println( line ) ;
components = line.split( "\\s+" ) ;

if ( (2 < components.length) && (components[1].equals("P:")) )
{ System.out.println( components[2] ) ; }
}

}
// ====================================================================
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic