Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What to import to use IOUtils.toString()?

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

like image 832
user2380101 Avatar asked May 14 '13 04:05

user2380101


People also ask

What does IOUtils copy do?

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.

What is Apache Commons IO used for?

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.


2 Answers

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"); 
like image 94
Fryta Avatar answered Sep 17 '22 15:09

Fryta


import org.apache.commons.io.IOUtils;

like image 22
kracejic Avatar answered Sep 17 '22 15:09

kracejic