File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Path to File Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Badass: Making Users Awesome this week in the Game Development forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Path to File" Watch "Path to File" New topic

Path to File

Eugene Armistead

Joined: Jul 12, 2001
Posts: 10
Can anyone tell me if there is an easy way to convert a String object that represents a path to a File object?
I have a method that accepts a File object as an argument, but I have a String that that is the path to that file, i.e. "c:\MyProgs\data.txt" and I'd like to pass a reference to the File "data.txt"
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
There is a file constructor that you can use.
do this...
File f = new File("c:\MyProgs\", "data.txt" );
Then send f to your method...
Check the API to verify this.


So much trouble in the world -- Bob Marley
timothy zimmerman
Ranch Hand

Joined: Jun 26, 2001
Posts: 149
There is also a File constructor which takes a single String representing teh lcoation of the file
File f = new File( "C:\MyProgs\data.txt")
Eugene Armistead

Joined: Jul 12, 2001
Posts: 10
Thanks for the tips. They work just fine!
I agree. Here's the link:
subject: Path to File