Answer the question
In order to leave comments, you need to log in
How to get the physical address of a file using Java (not mounted partition)?
I need to write a function that will return the total amount of available disk space according to the list of input strings (directory path): long getTotalSpace(String pathDir1, String pathDir2){ ... }.
The problem is that pathDir1 and pathDir2 can be on the same mounted partition, in which case TotalSpace does not need to be summed. I can't determine the real path to the file
. Tried to use toRealPath(), getCanonicalPath(), getAbsolutePath() - displays a symbolic link
. For example, I specify pathDir1 = /dir1/dor1_1 - displays the same thing, but you need: /dev/mapper/disk_01/dor1_1
Please tell me the solution
Answer the question
In order to leave comments, you need to log in
Look towards the java.nio.file package .
For example, the Files class has an interesting isSameFile method. I quickly jotted down the following code:
import java.nio.file.Files;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Path;
public class UnixPath{
public static void main(String[] args) throws Exception {
Path path1 = FileSystems.getDefault().getPath(args[0]);
Path path2 = FileSystems.getDefault().getPath(args[1]);
System.out.println(Files.isSameFile(path1, path2));
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question