1

Here is the code I already have, I need to next dynamically store the contents of the file we were given into the string array pieLabels. I cannot figure out how to do this though, any help would be greatly appreciated!

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;
    }

}
John C
  • 11
  • 1
  • Possible duplicate of [How to create a Java String from the contents of a file?](http://stackoverflow.com/questions/326390/how-to-create-a-java-string-from-the-contents-of-a-file) – Perdomoff Nov 09 '15 at 22:09
  • use a `while` loop. That should help – 3kings Nov 09 '15 at 22:10
  • Why did you set "ios" tag? – user996142 Nov 09 '15 at 22:37
  • Confusing; from your question it is unclear, for instance, as to whether the contents of the file are text (although I guess this is the case), whether the file has several lines and if so, what is the format of one line etc. – fge Nov 09 '15 at 22:42

0 Answers0