3

I am trying to use the FileUtils.writeStringToFile() method of the Apache Commons IO. Every bit of documentation says that I can do this:

FileUtils.writeStringToFile(File, String with data, boolean append);

I want this method, because I want the data to be written to the end of the file each time.

However, in Eclipse, it keeps telling me that this method does not exist. The only two I have are:

FileUtils.writeStringToFile(File, String with data);
FileUtils.writeStringToFile(File, String with data, String encoding);

I corrected my POM file to now have this dependency:

<dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.4</version>
</dependency>

Can someone please tell me what I am doing wrong?

snowfi6916
  • 697
  • 4
  • 9
  • 21

2 Answers2

5

Version 1.3.2 doesn't have this method, use a newer version of commons-io

<dependency>
    <groupId>commons-io</groupId>
    <artifactId>commons-io</artifactId>
    <version>2.4</version>
</dependency>

Check the FileUtils 2.4 javadoc

Rangel Preis
  • 394
  • 1
  • 7
  • I replaced the old dependency in my POM file with this one. I am still having the same problem. It says that the method with the boolean doesn't exist. – snowfi6916 Apr 16 '13 at 19:20
  • Check your Maven dependencies under eclipse to confirm that your project are using the 2.4 version also run the Maven Update Project, forcing to update dependences or execute a project clean. – Rangel Preis Apr 16 '13 at 19:28
  • When I run Maven Install, it is putting "commons-io-2.4.jar" into the Target folder. I also ran Update Project. I am STILL having the same problem... – snowfi6916 Apr 16 '13 at 19:35
  • Unfortunately I have no way to tell what is wrong with your environment, I can only guarantee that the method you want to use is available in version 2.4. I would suggest a conflict of libraries but this should not be the problem. – Rangel Preis Apr 16 '13 at 19:45
0

Turns out I was adding the Tomcat library files as well as the JRE library files to my project. Because when I deleted commons-io from my POM, I still had FileUtils available.

I had to get rid of the Tomcat library files from my build path, and once I put commons-io back in, it worked.

snowfi6916
  • 697
  • 4
  • 9
  • 21