自己定义 了一个ReadTxtFile类,在主程序引用时,显示方法未定义 ,怎么解决呀:
下面是ReadTxtFile类:
package test;
import java.io.*;
public class ReadTxtFile {
public readTxt(String filePath) {
try {
File file = new File(filePath);
if(file.isFile() && file.exists()) {
InputStreamReader isr = new InputStreamReader(new FileInputStream(file), "utf-8");
BufferedReader br = new BufferedReader(isr);
String lineTxt = null;
while ((lineTxt = br.readLine()) != null) {
System.out.println(lineTxt);
}
br.close();
} else {
System.out.println("no exit");
}
} catch (Exception e) {
System.out.println("wrong doing");
}
}
}
下面是主程序 :
package test;
import test.ReadTxtFile;
public class Read {
public static void main(String[] args) {
String filePath = "F:\\javawork\\readtxtfile\\mdata.txt";
ReadTxtFile f = new ReadTxtFile();
f.readTxt(filePath);
}
}
下面是结果 显示:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method readTxt(String) is undefined for the type ReadTxtFile
at test/test.Read.main(Read.java:7)