• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Path to File

 
Eugene Armistead
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
timothy zimmerman
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the tips. They work just fine!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic