Android TEXT File Load (Error with BufferedInputStream Argument)

Asked 1 years ago, Updated 1 years ago, 359 views

I'm trying to load a text file on Android.
BufferedInputStream causes an error.

The content is
InputStream is requested as an argument for BufferedInputStream, but InputStramReader is passed. That's what it is.

Required type: InputStream
Provided type: InputStreamReader

I checked and found that InputStream has been inherited by InputStreamReader in the abstract class, so there seems to be no problem.
Also, as a process, FileInputStream reads as bytes and InputStreamReader text bytes
I understood that BufferedInputStream will buffer to the end of the line...

When I went to look at the code on the Internet, I found myself passing InputStreamReader to the BufferedInputStream argument in the same way.
Why is it an error?

protected void onStart(){
        super.onStart();

        try{

            FileInputStream infs=openFileInput(aaa.txt);
            BufferedInputStream bfin = new BufferedInputStream(newInputStreamReader(infs));

        }catch(FileNotFoundExceptione){

            e.printStackTrace();

        }

    }

I look forward to your kind cooperation.

java android

2022-09-30 21:55

1 Answers

It has been resolved by the comments.
The reason is the misunderstanding between BufferedInputStream and BufferedReader...


2022-09-30 21:55

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.