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 :)

3
  • need to import 3rd party .jar file at you class path Commented Dec 8, 2015 at 13:35
  • 1
    If you have many dependencies - use maven/gradle. If you don't - download the jar and include it in your libraries using the class path. Commented Dec 8, 2015 at 13:35
  • may i know which editor are you using ? eclipse/netbean ? Commented Dec 8, 2015 at 13:39

4 Answers 4

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.

Sign up to request clarification or add additional context in comments.

Comments

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())); 

Comments

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

1 Comment

@vishalgajera has provided you detail steps in his answer.
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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.