Why do I get the error “File cannot be resolved to a type”?

后端 未结 4 1706
天涯浪人
天涯浪人 2020-12-10 17:26

Here\'s part of my code

try{

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

    while ((line= in.readLine())!=\"exit\"){

            


        
相关标签:
4条回答
  • 2020-12-10 18:05

    Chances are you've just missed:

    import java.io.File;
    

    from the top of your source file.

    You could use

     import java.io.*; 
    

    I typically use single-type imports.

    0 讨论(0)
  • 2020-12-10 18:05

    You most likely forgot to import java.io.File but essentially the compiler is telling you it can't find the "File" class.

    See this java error page specific to "File cannot be resovled to a type" for more info.

    0 讨论(0)
  • 2020-12-10 18:07

    I received this error once, even though I had already imported java.io.File. I think it was some weird, temporary Eclsipse glitch. When I made other changes to the code, then saved it again, the error resolved itself.

    0 讨论(0)
  • 2020-12-10 18:16

    You need to include either

    import java.io.File;
    

    or

    import java.io.*;
    

    at the top of your source file.

    0 讨论(0)
提交回复
热议问题