Are you asking about escape character issues?
If that is the case then use forward slashes instead of backward slashes like
"C:/Users/You/Desktop/test.txt"
instead of
"C:\Users\You\Desktop\test.txt"
If you know the name of the file, of course it's simply
new File("./myFileName")
If you don't know the name, you can use the File object's list() method to get a list of files in the current directory, and then pick the one you want.
Yes, you can get it from the File object by using File.toPath(). Keep in mind that this is only for Java 7+. Java versions 6 and below do not have it.
From the documentation:
Paths associated with the default
providerare generally interoperable with thejava.io.Fileclass. Paths created by other providers are unlikely to be interoperable with the abstract path names represented byjava.io.File. ThetoPathmethod may be used to obtain a Path from the abstract path name represented by a java.io.File object. The resulting Path can be used to operate on the same file as thejava.io.Fileobject. In addition, thetoFilemethod is useful to construct aFilefrom theStringrepresentation of aPath.
(emphasis mine)
So, for toFile:
Returns a
Fileobject representing this path.
And toPath:
Returns a
java.nio.file.Pathobject constructed from the this abstract path.