text file
Dietel10004 How to Program In Java R IN Dietal & Dietal Prentice Hall 06-09-08
Flanag0204 Java In a Nutshell C OUT David Flanagan O'Reilly 03-06-20
END
99100452 John Smith #5 Hillview Drive, Tunapuna UnderGrad 5
02154632 Chris Chami #16 Insame Lane, St. Anns Lecturer 0
END
Data are separated by tabs
[code=java]
public class Book{
private String ISBN;
private String title;
private String type;
private String status;
private String author;
private String publisher;
private String dateborrowed;
public Book( String isb, String tit, String typ, String sta, String aut, String pub, String dateb )
{
ISBN = isb;
title = tit;
type = typ;
status = sta;
author = aut;
publisher = pub;
dateborrowed = dateb;
}
public String toString(){
String str;
str = "ISBN" + ISBN+"\n"+
"title " + title+"\n"+
"type " + type+"\n"+
"status " + status+"\n"+
"author " + author+"\n"+
"publisher " + publisher+"\n"+
"dateborrow ed " + dateborrowed+"\ n";
return str;
}
}//End Book class [/code]
[code=java]
import java.io.*;
import java.util.*;
public class Test1{
static Book[] book = new Book [ 100 ];
public static void main(String [] args)throws IOException{
Scanner input = new Scanner(new FileReader("db. txt"));
input.useDelimi ter("\t"); //Set scanner to break on tabs
int a = 0;
String x = input.next();
while(!(x.equal s("END"))){
book[a] = new Book(x, input.next(),in put.next(),inpu t.next(),input. next(),input.ne xt(),input.next ()); //noSuchElementEx ception
a++;
x = input.next();
}
for(int i = 0; i < a; i++){
System.out.prin tln(book[i].toString());
}
}//end class main
}//end class test
[/code]
I am trying to read the text file above and store the first 2 rows in book and array of objects. Every time I run the program it gives a noSuchElementEx ception. I am reading 7 text strings , I cannot understan why. Please help.
Dietel10004 How to Program In Java R IN Dietal & Dietal Prentice Hall 06-09-08
Flanag0204 Java In a Nutshell C OUT David Flanagan O'Reilly 03-06-20
END
99100452 John Smith #5 Hillview Drive, Tunapuna UnderGrad 5
02154632 Chris Chami #16 Insame Lane, St. Anns Lecturer 0
END
Data are separated by tabs
[code=java]
public class Book{
private String ISBN;
private String title;
private String type;
private String status;
private String author;
private String publisher;
private String dateborrowed;
public Book( String isb, String tit, String typ, String sta, String aut, String pub, String dateb )
{
ISBN = isb;
title = tit;
type = typ;
status = sta;
author = aut;
publisher = pub;
dateborrowed = dateb;
}
public String toString(){
String str;
str = "ISBN" + ISBN+"\n"+
"title " + title+"\n"+
"type " + type+"\n"+
"status " + status+"\n"+
"author " + author+"\n"+
"publisher " + publisher+"\n"+
"dateborrow ed " + dateborrowed+"\ n";
return str;
}
}//End Book class [/code]
[code=java]
import java.io.*;
import java.util.*;
public class Test1{
static Book[] book = new Book [ 100 ];
public static void main(String [] args)throws IOException{
Scanner input = new Scanner(new FileReader("db. txt"));
input.useDelimi ter("\t"); //Set scanner to break on tabs
int a = 0;
String x = input.next();
while(!(x.equal s("END"))){
book[a] = new Book(x, input.next(),in put.next(),inpu t.next(),input. next(),input.ne xt(),input.next ()); //noSuchElementEx ception
a++;
x = input.next();
}
for(int i = 0; i < a; i++){
System.out.prin tln(book[i].toString());
}
}//end class main
}//end class test
[/code]
I am trying to read the text file above and store the first 2 rows in book and array of objects. Every time I run the program it gives a noSuchElementEx ception. I am reading 7 text strings , I cannot understan why. Please help.
Comment