Pregunta

I'm having trouble with using a buffered readers. I've learned that they aren't given a string, they're typically given another reader, so here I was instructed to use InputStreamReader. I keep getting this "no suitable constructor found for BufferedWriter(String)" error on 2 of my BR's, one for input and another for output.

This is how all my BR's are constructed:

BufferedReader inStream = new BufferedReader(new InputStreamReader(inFile));

and here is some other info on the errors:

BufferedReader inStream = new BufferedReader(new InputStreamReader(inFile));
                                             ^
constructor InputStreamReader.InputStreamReader(InputStream,CharsetDecoder) is not applicable
  (actual and formal argument lists differ in length)
constructor InputStreamReader.InputStreamReader(InputStream,Charset) is not applicable
  (actual and formal argument lists differ in length)
constructor InputStreamReader.InputStreamReader(InputStream,String) is not applicable
  (actual and formal argument lists differ in length)
constructor InputStreamReader.InputStreamReader(InputStream) is not applicable
  (actual argument String cannot be converted to InputStream by method invocation conversion)

Thanks in advance.

¿Fue útil?

Solución

If you want to input a String to your BufferedReader, you can pass a java.io.StringReader instance to the constructor:

BufferedReader br = new BufferedReader(new StringReader("some string"));
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top