Solved

How do I check available space on a drive?

Posted on 2001-06-04
8
201 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
 

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
mergeTwo  challenge 13 72
countHi2 challenge 7 44
VB Script to add site to Java Exception List 4 18
Java DateChooser? 3 14
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This video teaches viewers about errors in exception handling.

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now