开发者

how to get free space of unc path in java code?

I want to know the free space on UNC path(network path like \server\foldername) using java. I found a sample to know the free space on local drive:

import java.io.File;  

public class GetFreeSpace  {  
    public static void main(String[] args){  
        File file = new File("C:\\Hello.txt开发者_如何学运维");  
        long value = file.getFreeSpace();  
        System.out.println("Total free space available in the file is "+value+" B");  
   }  
}

But this doesn't work for UNC path.


Be careful, because File.getFreeSpace() was introduced in Java 6, which means your application will not be executable on earlier platforms.

Regarding your question though, JVM can give you space for any UNC path (read here). I guess you just missed to escape the backlashes in the File constructor. Here's an example of usage:

System.out.println(new File("\\\\192.168.0.1\\share").getFreeSpace());

returning the amount of bytes 9996869632.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜