简体   繁体   中英

How to resolve 'readLines' error in Android Studios

I'm currently building an app with Java on Android Studios but I ran into a problem.

items = new ArrayList<>(FileUtils.readLines(getDataFile(), Charset.defaultCharset()));

I get an error from this line saying 'cannot resolve method readLines'

My dependencies in my build.gradle are as followed

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'commons-io:commons-io:2.6' //First tried this one
    implementation 'org.apache.commons:commons-io:1.3.2' //Then tried this one
}

The bottom two lines are what I tried to use to solve the issue but I still get the error.

I also have import android.os.FileUtils; in my java class but still nothing. Please help!

Use

import org.apache.commons.io.FileUtils;

Worked for me.

Try implementation 'commons-io:commons-io:2.11.0' from https://commons.apache.org/proper/commons-io/dependency-info.html . Then import it in your project like this import org.apache.commons.io.FileUtils; . Make sure you're not importing android.os.FileUtils already.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM