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.
I believe StringWriter
is what you're looking for.
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 File
in Java! Well, aside from tasks like checking permission, creating, etc.
All I/O in Java and Scala is based on one of two concepts:
InputStream
and OutputStream
Reader
and Writer
What you do is create one of these classes passing a File
as parameter. So, if whatever API you are using is intent on receiving a File
, you can't do anything about it. However, APIs will usually take one of the above classes, not a File
, 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 a String
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With