This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Hands On Software Engineering with Python and have Brian Allbey on-line!
See this thread for details.
Win a copy of Hands On Software Engineering with Python this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

How do i get the drive names  RSS feed

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.
Posts: 20092
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 class to read in the directory you get back from a "new"/")" 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.
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's the static 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\)
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* ;

* <P>
* <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] ) ; }

// ====================================================================
God is a comedian playing for an audience that is afraid to laugh - Voltair. tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!