我有第三方库功能,只接受Reader作为参数。我有String,我需要传递给函数。我怎么做 ?
String s = "Some String";
StringReader sReader = new StringReader(s);
// 3rd Party Function Definition is public File saveResult(Reader source);
我可以像文件aFile = saveResult(sReader)那样做; ?或者我应该创建缓冲区并首先调用read()吗?
我尝试了两种方式,并且我一直在获取空指针异常。
答案 0 :(得分:3)
希望这足以满足您的目的:
String string = "Some String";
StringReader stringReader = new StringReader(string);
File fileName = saveResult(stringReader); // calling Third party library method