Caffeinated Coder
Caffeinated Coder

Reputation: 680

I am writing a String to a text file. but null is getting printed

I have declared and initialed say a String temp = null;

through the program i am changing the value of temp by

temp = temp + folders[i] + newline;

and then write this String temp to a text file.

Now the issue is, every time I write it to the file, the word "NULL" gets printed too.

Please suggest me a work around.

Upvotes: 2

Views: 2949

Answers (2)

Chandra Sekhar
Chandra Sekhar

Reputation: 19502

temp = temp + folders[i] + newline;

is

temp = null + folders[i] + newline;

so it will print null in the file use "" instead

Upvotes: 1

jcomeau_ictx
jcomeau_ictx

Reputation: 38442

initialize temp to "" instead of null

Upvotes: 7

Related Questions