Java BufferedReader

2019-08-08 02:53发布

问题:

I'm looking at this tutorial about BufferedReader at youtube

https://www.youtube.com/watch?v=yofFVbARIRU

I write the code exactly as he does but I can't get it to work. I cant get the BufferedReader code to work even though I imported it with

import java.io.*;

InputStreamReader stream = new InputStreamReader(System.in);
BufferedReader reader = new BufferedReader (stream);

I solved it with this code:

InputStreamReader stream = new InputStreamReader(System.in);
java.io.BufferedReader reader = new java.io.BufferedReader (stream);

And this works as well:

java.io.BufferedReader reader = 
new java.io.BufferedReader (new InputStreamReader(System.in));

Could someone explain to me what's wrong in the first code? Because it works for him who's giving the tutorial

回答1:

You've likely got your own class that you've named BufferedReader and whose name is clashing with the core class and thus confusing the Java compiler. Rename it!