这是我已经拥有的代码,我需要接下来动态地将我们给出的文件的内容存储到字符串数组pieLabels中。我无法弄清楚如何做到这一点,任何帮助将不胜感激!
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Scanner;
public class P9 implements Interface{
String[] pieLabels;
double[] pieElements;
double[] barElements;
double[] secondBarElements;
double[] lineElements;
double[] lineSecond;
double[] lineThird;
@Override
public boolean readFile(String filename){
try {
int pieNum = 0; int barNum = 0; int lineNum 0;
Scanner fileReader = new Scanner(new File(filename));
if(fileReader.hasNextInt()){
pieNum = fileReader.nextInt();
}
if(fileReader.hasNextInt()){
barNum = fileReader.nextInt();
}
if(fileReader.hasNextInt()){
lineNum = fileReader.nextInt();
}
//this is where I should store it
fileReader.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
return false;
}
@Override
public String getTitle(eType type) {
// TODO Auto-generated method stub
return null;
}
@Override
public String[] getLabels(eType type) {
// TODO Auto-generated method stub
return null;
}
@Override
public double[] getData(eType type, int series) {
// TODO Auto-generated method stub
return null;
}
}