Y
Y
Ytsu Ytsuevich2014-12-26 00:58:49
Java
Ytsu Ytsuevich, 2014-12-26 00:58:49

Java. Where is the getCanonicalFile method in the new IO???

In the old method, you could get the full ( absolute ) path of the current directory:

new File(".").getCanonicalPath();                   // абсолютный путь

// если есть переменная типа File то:
file.getCanonicalPath();

Can you do it like this
new File(".").getCanonicalFile().toPath()();       // абсолютный путь

// если верху где-то переменная типа Path то:
path.toFile().getCanonicalPath()

But calling extra methods is not the point... (because of toFile a new instance is created) Is there really no canonical path
in the new API ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Bykov, 2015-01-29
@jusio

The official doc says to use Path.toRealPath or Path.normalize instead of File.getCanonicalPath or File.getCanonicalFile

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question