其他阶级差别调用方法我有3个班,Mainn,ReadFile的,和条目。在主类和Java中
ReadFile的基本上是我的类,它的所有文件I/O的东西。
我怎么能够访问我的Mainn类中的ReadFile就好了,但是当我试图在条目“e.openFile()”中访问它时,我得到一个表示标识符预期的错误。
我知道这可以通过在进入制作一个重载的方法OpenFile()是固定的,但是这是为什么需要输入,而不是在主类Mainn?
package homework6;
public class mainn {
public static void main(String[] args){
ReadFile r = new ReadFile();
r.openFile();
//r.readFile();
r.skipFirst();
String x[] = r.getData();
String y[] = r.getData();
String z[] = r.getData();
System.out.println(x[0] + "," + x[1]);
System.out.println(y[0] + "," + y[1]);
System.out.println(z[0] + "," + z[1]);
r.closeFile();
}
}
的ReadFile:
package homework6;
import java.util.*;
import java.io.*;
public class ReadFile {
Scanner x = null;
public void openFile(){
try{
x = new Scanner(new FileInputStream(
"C:\\Users\\Rohan Vidyarthi\\workspace\\Data.csv"));
}
catch(FileNotFoundException e){
System.out.println("File not found error");
}
}
public void readFile(){
while (x.hasNextLine())
System.out.println(x.nextLine());
}
public void skipFirst(){
x.nextLine();
}
public String[] getData(){ //returns String[] with Date and ADJ Close
String[] temp;
String[] out = new String[2];
temp = (x.nextLine()).split(",");
out[0] = temp[0];
out[1] = temp[6];
return out;
}
public boolean checker(){
return x.hasNextLine();
}
public void closeFile(){
x.close();
}
}
类条目:
package homework6;
public class Entry extends ReadFile{
ReadFile e = new ReadFile();
e.openFile();
double minn = Double.MAX_VALUE;
double maxx = Double.MIN_VALUE;
/*public String[] rMax(){
String[] temp1;
String[] temp2;
}
*/
}
你为什么认为一个条目应该是一个读文件?为什么两个类之间的继承? – GhostCat
我有一个CSV文件,其中有很多数字,实际上我不知道我是新的,不知道什么时候它适合做出新的类哈哈.. – Panthy
你真的想看看。继承不仅仅是将“扩展”放在某个类名后面。 A延伸意味着“A是B”......在你的情况下这会有意义吗?是输入文件吗?获得这样的东西与获得“有效”的代码一样重要! – GhostCat