3

I have 3rd party library function which only takes Reader as parameter. And I have String that I need to pass into function. How do I do that ?

String s = "Some String";
StringReader sReader = new StringReader(s);

// 3rd Party Function Definition is public File saveResult(Reader source);

Can I do as File aFile = saveResult(sReader); ? Or Should I create buffer and call read() first ?

I tried both way, and I am keep getting null pointer exception.

1
  • 3
    Can you please provide details on the exception you receive? Commented Feb 21, 2012 at 0:45

1 Answer 1

6

Hope this should be enough to serve your purpose:

String string = "Some String";
StringReader stringReader = new StringReader(string);
File fileName = saveResult(stringReader); // calling Third party library method
Sign up to request clarification or add additional context in comments.

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.