---
title: "File Size"
author: "louisling"
date: "2009-09-01T15:25:58Z"
tags: ["F#", "Java"]
slug: "file-size"
draft: false
lastmod: "2009-09-01T15:25:58Z"
id: 460080
url: "https://louisling.iteye.com/blog/460080"
---

```java
public static void main(String[] args) throws IOException {
    File file = new File("F:");
    if (file.exists()) {
        prt("Total:", file.getTotalSpace());
        prt("Usable:", file.getUsableSpace());
        prt("Free:", file.getFreeSpace());
    }
}

static void prt(String desc, long size) {
    double m = size / (1024 * 1024);
    double g = m / 1024;
    System.out.printf("%s %.2f G / %.2f M %n", desc, g, m);
}
```