1

I have following task: to make application for uploading data into FTP server using apache.commons.net.FTPClient, etc. There is method client.storeFile() which allows to upload file (it requires InputStream as 1 of method parameters). But I want to make txt file into server which should contain array of strings - array is variable of program. Should I make file, put strings into it and transfer this file into method, or there is stream which allow to store strings in memory without making file? Thank you, anyway.

2 Answers 2

1

There is ByteArrayOutputStream that you can use

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you, I can store my strings into BAOS. But how should I get InputStream from ByteArrayOutputStream?
with a ByteArrayInputStream as in new ByteArrayInputStream(baos.toByteArray())
I think you should use directly the ByteArrayInputStream with String.getBytes
1 need 1 think also - how can I transfer string into next line? If I use files I can use writeLine(), but I don't know how can I do it for bytes.
1

You can use StringBufferInputStream, but as you have an array of Strings, you might need to concatenate all of them first, or use a SequenceInputStream generating all the sub input streams...

I'd go for the second, combined with a lazy enumeration, if your array is large.

By the way, StringBufferInputStream is deprecated, so might want to use the ByteArrayInputStream and String.getBytes(...) methods instead.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.