3

I have this code in my java project, which reads a file and converts it into a string.

String txt = FileUtils.readFileToString(text);

It uses this class https://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/FileUtils.html

How do I import this into my project?

Thanks :)

Bruce
  • 41
  • 8

4 Answers4

2

If you are using Ant as a build in tool then below solution works,

Step - 1: download .jar file from here,

Step - 2: Then after add it into your class path likewise, Project right click -> properties

enter image description here

Step 3 : find Jar from you machine, and add it to your class path. likewise,

enter image description here

Click -> OK.

Now, Your problem has been resolved.

Community
  • 1
  • 1
Vishal Gajera
  • 4,137
  • 5
  • 28
  • 55
2

First of all you are looking for deprecated method. I suggest you should not use deprecated methods if possible.

Secondly, if you just want to get content of file in String, you can do it in following way with java.nio.file.Files and without using any third party library.

File file = new File("abc.txt");
String txt = new String(Files.readAllBytes(file.toPath()));
akash
  • 22,664
  • 11
  • 59
  • 87
1

Include commons-io jar in build path of your project by downloading it from Apache site -

https://commons.apache.org/proper/commons-io/download_io.cgi

Murli
  • 1,258
  • 9
  • 20
1

Try following what Rene said here: Add commons-io dependency to gradle project in Android Studio

You can also try to drag the jar file under Jar folder of lib after downloading it, then right click on the Jar file and select the "Add as library" option. Then select your app from the dialog box.

Community
  • 1
  • 1
Icy
  • 17
  • 4