I wrote a small program to read a csv file...I used buffered reader for that... My code looks like this:
package files;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import bk.bk;
public class QwithLinkedList{
public static void main(String args[]) throws Exception{
FileReader f=new FileReader("G:/bk.csv");
BufferedReader br=new BufferedReader(f);
String line;
while((line=br.readLine())!=(null)){
System.out.println(line);
}
}
}
Above is perfect code but my question is that I'm getting an exception with this code :
package files;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import bk.bk;
public class QwithLinkedList{
public static void main(String args[]) throws Exception{
FileReader f=new FileReader("G:/bk.csv");
BufferedReader br=new BufferedReader(f);
String line;
while(!(line=br.readLine()).equals(null)){
System.out.println(line);
}
}
}
The output for the above code is this :
a1
bk
abc
def
ghi
jkl
bharath
Exception in thread "main" java.lang.NullPointerException
at files.QwithLinkedList.main(QwithLinkedList.java:14)
Someone please explain why it is giving an exception with the above code. Moreover if(a!=b) and !a.equals(b) are't they same ?