diskspace

How to find how much disk space is left using Java?

隐身守侯 提交于 2019-11-26 11:20:06
How to find how much disk space is left using Java? Kredns Just look at the File class documentation . This is one of the new features in 1.6. These new methods also include: public long getTotalSpace() public long getFreeSpace() public long getUsableSpace() If you're still using 1.5 then you can use the Apache Commons IO library and its FileSystem class prunge Java 1.7 has a slightly different API, free space can be queried through the FileStore class through the getTotalSpace() , getUnallocatedSpace() and getUsableSpace() methods. NumberFormat nf = NumberFormat.getNumberInstance(); for (Path

How to check if IOException is Not-Enough-Disk-Space-Exception type?

戏子无情 提交于 2019-11-26 08:10:03
问题 How can I check if IOException is a \"Not enough disk space\" exception type? At the moment I check to see if the message matches something like \"Not enough disk space\", but I know that this won\'t work if the OS language is not English. 回答1: You need to check the HResult and test against ERROR_DISK_FULL (0x70) and ERROR_HANDLE_DISK_FULL (0x27), which can be converted to HResults by OR'ing with 0x80070000. For .Net Framework 4.5 and above, you can use the Exception.HResult property: static

Find size and free space of the filesystem containing a given file

不打扰是莪最后的温柔 提交于 2019-11-26 04:39:58
问题 I\'m using Python 2.6 on Linux. What is the fastest way: to determine which partition contains a given directory or file? For example, suppose that /dev/sda2 is mounted on /home , and /dev/mapper/foo is mounted on /home/foo . From the string \"/home/foo/bar/baz\" I would like to recover the pair (\"/dev/mapper/foo\", \"home/foo\") . and then, to get usage statistics of the given partition? For example, given /dev/mapper/foo I would like to obtain the size of the partition and the free space

Cross-platform space remaining on volume using python

允我心安 提交于 2019-11-26 04:38:59
问题 I need a way to determine the space remaining on a disk volume using python on linux, Windows and OS X. I\'m currently parsing the output of the various system calls (df, dir) to accomplish this - is there a better way? 回答1: import ctypes import os import platform import sys def get_free_space_mb(dirname): """Return folder/drive free space (in megabytes).""" if platform.system() == 'Windows': free_bytes = ctypes.c_ulonglong(0) ctypes.windll.kernel32.GetDiskFreeSpaceExW(ctypes.c_wchar_p

How to find how much disk space is left using Java?

三世轮回 提交于 2019-11-26 02:21:30
问题 How to find how much disk space is left using Java? 回答1: Have a look at the File class documentation. This is one of the new features in 1.6. These new methods also include: public long getTotalSpace() public long getFreeSpace() public long getUsableSpace() If you're still using 1.5 then you can use the Apache Commons IO library and its FileSystem class 回答2: Java 1.7 has a slightly different API, free space can be queried through the FileStore class through the getTotalSpace(),

Android get free size of internal/external memory

孤街醉人 提交于 2019-11-25 23:43:44
问题 I want to get the size of free memory on internal/external storage of my device programmatically. I\'m using this piece of code : StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath()); long bytesAvailable = (long)stat.getBlockSize() *(long)stat.getBlockCount(); long megAvailable = bytesAvailable / 1048576; Log.e(\"\",\"Available MB : \"+megAvailable); File path = Environment.getDataDirectory(); StatFs stat2 = new StatFs(path.getPath()); long blockSize = stat2