我有這個問題幾次,我創建了另一個類文件,主類文件找不到它。 這裏的主類文件:找不到另一個類文件的符號
package textfiles;
import java.io.IOException;
public class FileData
{
public static void main(String[] args)
{
String file_name = "Lines.txt";
try {
ReadFile file = new ReadFile(file_name);
String[] aryLines = file.OpenFile();
for(int i =0; i<aryLines.length; i++)
{
System.out.println(aryLines);
}
}
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;
int numberOfLines=0;
public ReadFile(String file_path)
{
path = file_path;
}
public String[] OpenFile() throws IOException
{
FileReader fr = new FileReader(path);
BufferedReader br = new BufferedReader(fr);
int numberOfLines = readLines();
String[] textData = new String[numberOfLines];
for(int i=0; i<numberOfLines; i++)
{
textData[i] = br.readLine();
}
br.close();
return textData;
}
int readLines() throws IOException
{
FileReader file_to_read = new FileReader(path);
BufferedReader bf = new BufferedReader(file_to_read);
String aLine;
while((aLine = bf.readLine()) != null)
{
numberOfLines++;
}
bf.close();
return numberOfLines;
}
}
我試着運行javac的TEXTFILES \ ReadFile.java和javac TEXTFILES \ FileData.java作爲this的建議。這是行不通的。我確定我已經編譯了ReadFile並修復了那裏的所有錯誤。 編譯器的錯誤,我得到的是:
C:\Users\Liloka\Source>javac FileData.java
FileData.java:13: cannot find symbol
symbol : class ReadFile
location: class textfiles.FileData
ReadFile file = new ReadFile(file_name);
^
FileData.java:13: cannot find symbol
symbol : class ReadFile
location: class textfiles.FileData
ReadFile file = new ReadFile(file_name);
^
2 errors
我用記事本+ +和.CMD所以它不可能是一個IDE錯誤。 在此先感謝!
謝謝!這確實使它運行,但由於某種原因,我得到 「[Ljava.lang.String; @ 19821f」而不是「One」打印時。你知道這是爲什麼嗎? :S 謝謝:) – liloka
不客氣。將'System.out.println(aryLines)'改爲'System.out.println(aryLines [i])'。 [更多信息Array的toString()](http://stackoverflow.com/questions/7060016/why-does-tostring-method-in-java-doesnt-seem-to-work) – palacsint
謝謝..我可以'相信我錯過了第一個地方! – liloka