?
Solved

How do I check available space on a drive?

Posted on 2001-06-04
8
Medium Priority
?
229 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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 …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses
Course of the Month8 days, 20 hours left to enroll

764 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