• Post Reply Bookmark Topic Watch Topic
  • New Topic

Difficulty in getting hold of a binary file!  RSS feed

 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

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
 
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 174
Java Java ME Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?


Thanks!

Srinivas
 
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your replies.

I fixed it by checking the length of the

pdfData, it was zero, incase of blank file.

Cheers!
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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) ...".
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!