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

时间:2011-05-13 19:44:26

标签: java

这是我的代码的一部分

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 cannot be resolved to a type

有什么问题?

4 个答案:

答案 0 :(得分:15)

你很快就错过了:

import java.io.File;

来自源文件的顶部。

可以使用

 import java.io.*; 

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

答案 1 :(得分:5)

您需要包含

import java.io.File;

import java.io.*;

位于源文件的顶部。

答案 2 :(得分:0)

你很可能忘记导入java.io.File但基本上编译器告诉你它找不到“文件”类。

有关详细信息,请参阅特定于“File cannot be resovled to a type”的此java错误页面。

答案 3 :(得分:0)

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