can someone help me debug plzz
so i got this code....which should read and store 300 lines.....but it's not starting from the beginning of the text....its starting from the 2nd and sometimes the 5th line................someone help me debug
Code java:
import java.util.Scanner;
import java.io.File;
class copyofcode
{
public static void main (String args[])throws Exception
{
String[]text=new String[300];
File myfile = new File("alice.txt");
Scanner scan = new Scanner(myfile);
/* reading 20 lines and storing them and printing them out to the screen*/
for (int a=0; a<300; a++)
{
text[a] = scan.nextLine();
if(text[a]==null)
break;
System.out.println(text[a]);
}
scan.close(); //closing the file
}
}
Re: can someone help me debug plzz
Tried it out on my a text file containing:
"The King and Queen of Hearts were seated on their throne when they arrived,
with a great crowd assembled about them--all sorts of little birds and beasts,
as well as the whole pack of cards: the Knave was standing before them, in
chains, with a soldier on each side to guard him; and near the King was the
White Rabbit, with a trumpet in one hand, and a scroll of parchment in the
other. In the very middle of the court was a table, with a large dish of tarts
upon it: they looked so good, that it made Alice quite hungry to look at them--
`I wish they'd get the trial done,' she thought, `and hand round the
refreshments!'
But there seemed to be no chance of this, so she began looking at everything
about her, to pass away the time. "
And it worked fine with an added try catch, but worked fine without it just gave exception warning in the middle.