Reputation: 1099
I have an object of class File that represent a directory. I now want to create a new File object that refers to a file within that directory. The following code seems to work:
String filePath = myDirectory.getAbsoutePath().concat("\\myFileName");
File theFile = File(filePath);
But, I was wondering if there was a way to do it without the File --> String --> File conversion.
Thanks.
Upvotes: 0
Views: 89
Reputation: 5168
Use the constructor public File(File parent, String child)
like File newFile = new File(myDirectory, "myFileName");
See for example: http://www.java2s.com/Tutorials/Java/java.io/File/Java_File_File_parent_String_child_Constructor.htm
Upvotes: 2