I am trying to use IOUtils.toString() to read from a file. However, I am getting an error saying "IOUtils cannot be resolved."
What am I supposed to be importing to allow me to use this function?
String everything = IOUtils.toString(inputStream);
Thanks
Copies chars from a Reader to an Appendable . Copies chars from a Reader to bytes on an OutputStream using the specified character encoding, and calling flush. Copies chars from a Reader to bytes on an OutputStream using the specified character encoding, and calling flush.
Apache Commons IO is a library of utilities to assist with developing IO functionality. There are six main areas included: io - This package defines utility classes for working with streams, readers, writers and files. comparator - This package provides various Comparator implementations for Files.
import org.apache.commons.io.IOUtils;
If you still can't import add to pom.xml:
<dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> <version>2.5</version> </dependency>
or for direct jar/gradle etc visit: http://mvnrepository.com/artifact/commons-io/commons-io/2.5
Also since version 2.5 of commons-io method IOUtils.toString(inputStream) has been deprecated. You should use method with Encoding i.e.
IOUtils.toString(is, "UTF-8");
import org.apache.commons.io.IOUtils;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With