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;
}
}
他們在不同的文件?即。 FileData.java和ReadFile.java。如果不是,那是第一步。 – anonymous
使用cmd或終端或NetBeans,Eclipse等IDE嗎?此外,代碼必須位於名爲「FileData.java」和「ReadFile.java」的兩個不同文件中,名爲「textfiles」 – Arvind
的包中,同時從cmd /終端u編譯ur源代碼必須在包。嘗試運行這個編譯命令:javac textfiles \ *。java – Arvind