Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CLOSED - How do I import another class not in Java Library

Tags:

java

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

like image 549
Bruce Avatar asked Nov 16 '25 05:11

Bruce


2 Answers

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.

like image 196
Vishal Gajera Avatar answered Nov 18 '25 19:11

Vishal Gajera


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()));
like image 27
akash Avatar answered Nov 18 '25 20:11

akash