So I have a very long text file and using Scanner to load it takes about half an hour so I'm trying to switch over to BufferedReader and this is the code I have right now
public static void main(String[] args) {
// TODO Auto-generated method stub
BufferedReader Br1 = null;
BigInteger num = new BigInteger ("0");
String Line = "";
try {
Br1 = new BufferedReader (new FileReader("text.txt"));
System.out.println("Read line method");
Line = Br1.readLine();
while(Line != null) {
num = num.add(new BigInteger(Line));
System.out.println(Line);
Line = Br1.readLine();
}
System.out.println("number " + num);
} catch (IOException ioe) {System.out.println("error");}
}
To test it I made the text file 2 1 0 where all the numbers are on separate lines
I want it to give me a BigInteger 210 but instead it gives me 3, I tried messing around with different ways of adding to the BigInteger but I can't get it to work right. How should I do this?