Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How do I check available space on a drive?

Posted on 2001-06-04
8
Medium Priority
?
240 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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 800 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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 …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

604 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