我正在关注教程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;
}
}
答案 0 :(得分:0)
问题是JAVA COMPILER
在文件夹文本文件中寻找CLASS FILE
{ReadFile.class},所以按照这个来编译,
1 - &GT;使用此
编译ReadFilejavac -d . ReadFile.java
2 - &GT;使用此
编译FileDatajavac -d . FileData.java
注意:此目的
-d
是否会在编译期间创建适当的包。