I would like to know that if java/scala has the “string object that could act as file” as StringIO in python ? I figure that it would be better than writing and reading alot of temporary file. I prefer scala but java one should be fine too.
Share
It depends on how this is being used. You see, while you do stuff with a file in Python, you don’t do anything with a
Filein Java! Well, aside from tasks like checking permission, creating, etc.All I/O in Java and Scala is based on one of two concepts:
InputStreamandOutputStreamReaderandWriterWhat you do is create one of these classes passing a
Fileas parameter. So, if whatever API you are using is intent on receiving aFile, you can’t do anything about it. However, APIs will usually take one of the above classes, not aFile, and all of them have a string-version available.As for Scala, there’s also
scala.io.Stream, for which you can also create one based on aString.