Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Willie Howell   on Mar 22 In Java Category.

  
Question Answered By: Tomas Thompson   on Mar 22

I got it
Here is the code,
import java.io.*;
import java.util.*;

public class  GetDiscSpace
{
public static void main( String[] str )
{
Runtime rt = Runtime.getRuntime();
String strDiskSpace = null;
Process p = null;
String strOS = System.getProperty( "os.name" );
try
{
if( strOS.equals( "Windows 2000" ))
{
p = rt.exec("cmd.exe /c dir d:\\" );
}
else
{
// Windows xp
p = rt.exec("cmd.exe /c dir d:\\" );
}

InputStream inStream = p.getInputStream();
BufferedReader reader = new BufferedReader( new
InputStreamReader( inStream));
String strTemp;

while( (strTemp = reader.readLine()) != null )
{
strDiskSpace = strTemp;
}

System.out.println( strDiskSpace.trim() );
StringTokenizer sToken = new StringTokenizer(
strDiskSpace.trim() , " " );

if( sToken.hasMoreTokens())
{
System.out.println( "Free Space : " +
sToken.nextToken() );
}

p.destroy();
}
catch( Exception e )
{
System.out.println( e.getMessage());
}
}
}

Share: 

 

This Question has 2 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on DISK SPACE CALCULATION Or get search suggestion and latest updates.


Tagged: