In order to do some testing I want to create an instance of FileInputStream
from a String
variable instead of reading from a file.
Basically when the FileInputStream
reads bytes from a file, I want those bytes to come from a string variable instead of a file. Is there a way to maybe create a FileInputStream
instance to read from a byteArray[]
or some other way to make FileInputStream
to read from a String
variable instead from a file ?
Edit :
I am aware of how to create an InputStream
from a String
. My issue here is that the code I am testing uses a FileInputStream
to read form an actual file so I need to create an instance of FileInputStream
only.
Piece of code under test is :
final InputStream inputStream = new FileInputStream(inputFile);
Is there a way to modify this or use alternatives that would allow me to test it without having to read form an actual file ?
Duplicate
I have a distinct solution not implemented in any of the answers in the question that this question is marked duplicate of. The mediator has completely misjudged the whole question since none of those answers seem to work for me and the one that finally did work thanks to a suggestion by @Thilo, I cannot update here because of the duplicate stamp.