2014-02-06 65 views
0

我按照教程here,我一直试图让这个工作两天。编译FileData时出现此错误消息。我找不到错误

FileData.java:13: error: cannot find symbol 
      ReadFile file = new ReadFile(file_name); 
     ^
    symbol: class ReadFile 
    location: class FileData 

FileData.java:13: error: cannot find symbol 
      ReadFile file = new ReadFile(file_name); 
          ^
    symbol: class ReadFile 
    location: class FileData 

任何援助将不胜感激。

的代码如下:

package textfiles; 
import java.io.IOException; 


public class FileData 
{ 
    public static void main(String[] args) throws IOException 
    { 
     String file_name = "C:/test.txt"; 

     try 
     { 
      ReadFile file = new ReadFile(file_name); 
      String[] aryLines = file.OpenFile(); 

      int i; 
      for (i=0; i < aryLines.length; i++) 
      { 
       System.out.println(aryLines[i]); 
      } 
     } 

     catch (IOException e) 
     { 
      System.out.println(e.getMessage()); 

     } 

    } 
} 


package textfiles; 

import java.io.IOException; 
import java.io.FileReader; 
import java.io.BufferedReader; 

public class ReadFile 
{ 

    private String path; 

    public ReadFile (String file_path) //ReadFile Method 
    { 
     path = file_path; 
    } 

    public String[] OpenFile() throws IOException //OpenFile method 
    { 
     FileReader fr = new FileReader(path); 
     BufferedReader textReader = new BufferedReader(fr); 

     int numberOfLines = readLine(); 
     String[] textData = new String[numberOfLines]; 

     int i; 

     for (i=0; i < numberOfLines; i++) 
     { 
      textData[i] = textReader.readLine(); 
     } 

     textReader.close(); 
     return textData; 
    } 

    int readLine() throws IOException //readLines Method 
    { 
     FileReader file_to_read = new FileReader(path); 
     BufferedReader bf = new BufferedReader(file_to_read); 

     String aLines; 
     int numberOfLines = 0; 

     while ((aLines = bf.readLine()) !=null) 
     { 
      numberOfLines++; 
     } 
     bf.close(); 

     return numberOfLines; 

    } 
} 
+6

他们在不同的文件?即。 FileData.java和ReadFile.java。如果不是,那是第一步。 – anonymous

+0

使用cmd或终端或NetBeans,Eclipse等IDE吗?此外,代码必须位于名为“FileData.java”和“ReadFile.java”的两个不同文件中,名为“textfiles” – Arvind

+0

的包中,同时从cmd /终端u编译ur源代码必须在包。尝试运行这个编译命令:javac textfiles \ *。java – Arvind

回答

0

JAVA COMPILER是文件夹里面TEXTFILES寻找CLASS FILE {} ReadFile.class问题所以按照这个来获得编译,

1 - >编译的ReadFile使用这种

javac -d . ReadFile.java 

2 - >使用该

编译的FileData
javac -d . FileData.java 

注意:该

-d

目的是将编译过程中创建相应的软件包。