I am reading code out of a txt file which contains text in this format..
[text file]
Name of Project
Experiment One
cows, dogs, pigs, horses, sheep, goats
1,1,1,1,20,10
cowweight,dogweight,pigweight,horseweight,sheepweight,goatweight
560,50.5,54.3,641.1,35.4,42.5
deer,elk, moose
2,4,5
etc...
[text file]
I am trying to read in the numeric values to use for a program and am having some problems. My code looks like this
public class OpenFile {
throws FileNotFoundException {
FileInputStream fis = new FileInputStream(test.txt);
BufferedInputStream bis = new BufferedInputStream(fis);
DataInputStream dis = new DataInputStream(bis);
Scanner s= new Scanner(dis);
try{
s.nextLine();
s.nextLine();
s.nextLine();
int cow = s.nextInt(); System.out.println(cow);
int dog = s.nextInt(); System.out.println(dog);
int pig = s.nextInt(); System.out.println(pig);
int hor = s.nextInt(); System.out.println(hor);
int she = s.nextInt(); System.out.println(she);
int goa = s.nextInt(); System.out.println(goa):
s.nextLine();
double coww = s.nextDouble(); System.out.println(coww);
double dogw = s.nextDouble(); System.out.println(dogw);
double pigw = s.nextDouble(); System.out.println(pigw);
double horw = s.nextDouble(); System.out.println(horw);
double shew = s.nextDouble(); System.out.println(shew);
double goaw = s.nextDouble(); System.out.println(nmax):
S.nextLine();
///etc. and continues from there
When I run the code I get
1
1
1
1
20
Error: null
and the program ceases to show anything else.
I have run the code with various txt files of the same format and sometimes it will print something like this
1
Error: null
3
3
7
8
Any advice?