为什么我会收到错误“文件无法解析为某种类型”?

这是我的代码的一部分

try{ BufferedReader in= new BufferedReader(new InputStreamReader(System.in)); while ((line= in.readLine())!="exit"){ System.out.println("Enter command"); line=in.readLine(); Command currentCommand=new Command(line); File currentFile= new File(currentCommand.getLsPath()); 

方法currentCommand.getLsPath()返回一个字符串,这对于File Constracture是可修改的,但我仍然收到此错误: File cannot be resolved to a type

问题是什么?

你错过了很多机会:

 import java.io.File; 

从源文件的顶部。

可以

  import java.io.*; 

我通常使用单一类型的导入。

你需要包括

 import java.io.File; 

要么

 import java.io.*; 

在源文件的顶部。

您很可能忘记导入java.io.File但基本上编译器告诉您它无法找到“File”类。

有关详细信息,请参阅此特定于“ 文件无法恢复为某种类型 ”的java错误页面。

我曾经收到过这个错误,即使我已经导入了java.io.File。 我认为这是一些奇怪的,临时的Eclsipse故障。 当我对代码进行其他更改,然后再次保存时,错误自行解决。