Solved

How do I check available space on a drive?

Posted on 2001-06-04
8
206 Views
Last Modified: 2010-03-31
I am working on a project where I need to check if there is enough space to copy a file to a drive. Something that I can send a file size to and have it return true or false. I need a method that can look into a drive and determine if a certain number of bytes are available. Example, files from the C drive to the A drive. I can copy files over, but I need to test if there will be enough space to comlete the job.

Any direction would be helpful.
I am using JBuilder4 in a windows environment.

JDay
0
Comment
Question by:JDay
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 3

Expert Comment

by:shyamkumarreddy
ID: 6155091
Just use

java.lang.Runtime.freeMemory();
it will give u the freememory available in the system
then do arthimatic on the value.
if it is less then less space. else enough space

Cheers
Shyam
0
 
LVL 4

Expert Comment

by:rdov
ID: 6155285
Use a third party tool like JConfig that allows this type of access.
http://www.tolstoy.com/samizdat/jconfig.html
0
 

Expert Comment

by:motoras
ID: 6155979
There is no pure java solution for your problem. To find the available space on the drive you must use a native method. The java.lang.Runtime.freeMemory() returns the amount of memory disponible in JVM not on a hard drive.

0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

Author Comment

by:JDay
ID: 6156080
Shyam,

How would you check the A: drive(floppy disk) for available space? Do you have a response from motoras's comment?

JDay
0
 
LVL 3

Expert Comment

by:shyamkumarreddy
ID: 6158514
Hi JDay

I tried after the motoras has said.

The Available Space can be found using Runtime.totalMemory()

Will give ur current free space available in hard disk


Cheers
Shyam
0
 

Expert Comment

by:motoras
ID: 6159830
Dear JDay I think you have no ideea about the differnce between the available space on a hard drive and the amount of memory available for an application (in particular a JVM)
From java doc:

public long totalMemory()
Returns the total amount of memory in the Java Virtual Machine. The value returned by this method may vary over time, depending on the host environment.
Note that the amount of memory required to hold an object of any given type may be implementation-dependent.

Returns:
the total amount of memory currently available for current and future objects, measured in bytes.


0
 

Author Comment

by:JDay
ID: 6207267
Dear motoras,

I agree that it will return the java virtual machine memory.

I do have an "idea" about the difference between the different types of memeory!

Maybe Shyam doesn't.

This question still remains unsolved.

Java is so robust.
I feel like there would have to be some way to get available drive space.
JDay
0
 
LVL 1

Accepted Solution

by:
eattrig earned 200 total points
ID: 6239501
Utitize the Java Native Interface to write a wrapper class in C++ which will allow you access and give you the ability to "talk to the hardware".  Then use Windows API calls to write a C++ program that will return the total available drive space for a given drive.
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
servlet requestdispatcher include and forward differences 1 30
object oriented programming comparison 5 72
login form jsp example 2 25
Chrome and Firefox Java 5 32
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
The viewer will learn how to implement Singleton Design Pattern in Java.
This video teaches viewers about errors in exception handling.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question