It depends on how it is used. You see, while you are doing stuff with a file in Python, you're not doing anything with File in Java! Well, besides tasks like checking permission, creating, etc.
All I / O operations in Java and Scala are based on one of two concepts:
InputStream and OutputStreamReader and Writer
What you do is create one of these classes by passing the File as parameter. So, if any of the APIs you use intend to get a File , you can't do anything about it. However, the API, as a rule, takes one of the above classes, not File , and they all have an available version of the string.
As for Scala, then also scala.io.Stream , for which you can also create it based on String .
Daniel C. Sobral
source share