I am finding it hard to capture the content of a binary file.
Here is my code:
When the binary file is blank, control still goes into "if" instead of "else"!!!
How should I change the "if" condition so that, whenever the binary file is blank, I wanna execute "else"
Thanks
Srinivas
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35224
7
posted
0
What is the connection between "myInstance.getBin_File().toString().equals("")" and the "binary file being blank"? What kind of object is returned by the getBin_File() method? If it's a file, then the toString method does not return what you think it returns.
Also note that whenever binary data is involved, you should not be using string methods and string comparisons.
Here's a little offtopic, but you should always use "".equals(variable) instead of variable.equals("") to avoid null pointer exceptions.
forums UseR
Ranch Hand
Joined: Feb 24, 2009
Posts: 169
posted
0
Ulf Dittmer wrote:What is the connection between "myInstance.getBin_File().toString().equals("")" and the "binary file being blank"? What kind of object is returned by the getBin_File() method? If it's a file, then the toString method does not return what you think it returns.
Also note that whenever binary data is involved, you should not be using string methods and string comparisons.
Thanks for your reply.
How should I check if pdfData has any content in it ( I mean if pdfData is blank) ?
Can you please provide me a if condition check code ?
Zandis Murāns wrote:Here's a little offtopic, but you should always use "".equals(variable) instead of variable.equals("") to avoid null pointer exceptions.
That's where the !(null == ...) check comes in.
Which is also an issue. Never ever ever write !(value == variable). There is an operator for that, !=. Use it: value != variable.
Another thing is the extra pair of brackets in !(myInstance.getBin_File().toString().equals("")). The dot binds stronger than the !, so you can simply write !myInstance.getBin_File().toString().equals("").
forums UseR
Ranch Hand
Joined: Feb 24, 2009
Posts: 169
posted
0
Thanks for your replies.
I fixed it by checking the length of the
pdfData, it was zero, incase of blank file.
Cheers!
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35224
7
posted
0
srinivas chary wrote:
How should I check if pdfData has any content in it ( I mean if pdfData is blank) ?
Can you please provide me a if condition check code ?
Java arrays have a "length" attribute you can use, so the check would be something like "if (pdfData.length == 0) ...".