I'm reading some data from file.
String content = null;
File file=new File(str);
FileInputStream fis = null;
try {
fis = new FileInputStream(file);
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
byte byt[] = new byte[1024];
try {
while(fis.read(byt)!=-1)
{
content += new String(byt);
}
fis.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
File contains some text say Hello
.
when I read complete file it gives me string nullHello
. why it is so. and when I set content = ""
it gives me right string.
In first case jvm will not any memory to content object then while concatenating how it uses null as string ?