File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Path to File" Watch "Path to File" New topic
Author

Path to File

Eugene Armistead
Greenhorn

Joined: Jul 12, 2001
Posts: 10
Hi,
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"
Thanks,
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1506
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.

Bosun


Bosun (SCJP, SCWCD)
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
Greenhorn

Joined: Jul 12, 2001
Posts: 10
Thanks for the tips. They work just fine!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Path to File
 
Similar Threads
Could somebody give some ideas?
hyperlink to file on C: drive does not work
read text and stroe date to the array
Writing a class file to read text file.
reading a file from a parent directory??