3

I stumbled upon this problem when trying to play around with Apache commons IO third party API with Android Studio.

Basically when I try to call the FileUtils.readLines() method, there are 3 options:

  • readLines(File file) >>>> DEPRECATED
  • readLines(File file, String encoding)
  • readLines(File file, Charset encoding)

The first option has already been deprecated which means that I shouldn't use it anymore so instead I just type readLines(file,null) However, right now the problem is that Android Studio doesn't know which readLines() method signature I'm using because readLines(file,null) is valid for both the second and third method signature.

Screenshot below to further explain what I mean:

enter image description here

Can anyone please enlighten me on this? How can I tell Android Studio the particular method signature that I want to use for FileUtils.readLines()?

blue2609
  • 841
  • 2
  • 10
  • 25

1 Answers1

6

IDE can't guess what your null is. Whether it is String or Charset. You can try something like:

String encoding=null;
FileUtils.readLines(file, encoding);

But I think that wouldn't work since readLines method needs to know what encoding your file uses. So if for example your file uses UTF-8, you can write this

FileUtils.readLines(file, StandardCharsets.UTF_8);

Or you can try to use default charset, see this: How to Find the Default Charset/Encoding in Java?

And as Apache docs say, deprecated version readLines(File file) used default charset. You can write this to get an equivalent:

FileUtils.readLines(file, Charset.defaultCharset());
funbiscuit
  • 193
  • 2
  • 4
  • 12
  • Thanks a lot for that mate! Ohhhh I see, yeah I tried your suggestion with the **Charset.defaultCharset()** and it works haha. I also tried doing the **String encoding = null; FileUtils.readLines(file,encoding)** but yeah that doesn't work. Thanks so much! – blue2609 Aug 14 '18 at 07:11